tags:

views:

33

answers:

3

I am being fed a url that looks like this:

http://hamilton.kijiji.ca/c-buy-and-sell-sports-bikes-Kids-bike-W0QQAdIdZ215282410

I want to pull out the numbers after adIdZ

How can I pull these numbers off dynamically?

+2  A: 
s= 'http://hamilton.kijiji.ca/c-buy-and-sell-sports-bikes-Kids-bike-W0QQAdIdZ215282410'
s = s.replace( /\d+$/, '' )

Updated

s = 'http://hamilton.kijiji.ca/c-buy-and-sell-sports-bikes-Kids-bike-W0QQAdIdZ215282410'

s = s.match( /(\d+)$/ )
if ( s.length )
    alert( s[1] )
meder
that doesn't seem to do anything.
Wes
@Wes The regex \d+$ should capture all the digits from the end of the line and replace them w/ an empty string i.e. the variable s will hold the URL w/o those numbers. However, shouldn't it be in quotes? That may be the issue.
George Marian
@Wes - you have not really specified how you are replacing/modifying the urls. If you need to modify the `a` href then use `.attr`.
meder
Sorry, I need to create a variable that has those number in them. Not take them out. Either say, alert of s just shows the whole URL
Wes
Perfect, that worked!
Wes
A: 

Can't you just get the 8 last characters from the URL string?

Spidey
A: 

It's not entirely clear what you want to achieve. If you wish to strip, that is remove, the final id, meder gave the correct reply. If you wish to extract the id, it's a simple change from his code:

s= 'http://hamilton.kijiji.ca/c-buy-and-sell-sports-bikes-Kids-bike-W0QQAdIdZ215282410'
id = s.match(/\d+$/)
chryss