-1

I have a URL like this one:

/events/3*1*1*0*0*3*3*1/permalink/391013797602909/

or this one:

/*o*i*z*r*g/posts/3804270420760

I have censored the event ID and the user ID. Basically I want to get the Event ID and the permalink ID (long number), and the user ID and post ID. I am confused with how to do that with Javascript/jQuery.

Thanks!

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
Nadav S.
  • 2,429
  • 2
  • 24
  • 38
  • duplicate of http://stackoverflow.com/questions/6644654/parse-url-with-jquery-javascript – raddrick May 29 '12 at 15:41
  • RGB, that is NOT a duplicate, and guess what, I already saw this exact question. I am trying to parse the URL, and not just get a `GET` variable. Next time, you should read the question before voting down or writing wrong/not useful comments. – Nadav S. May 29 '12 at 15:44

2 Answers2

2

use .split("/"); on the url in question. That returns an array of strings split by the slash.

Jeff Watkins
  • 6,343
  • 16
  • 19
1

If you have a fixed format, you can use RegExp to match the patterns you want:

'/events/3*1*1*0*0*3*3*1/permalink/391013797602909/'
    .match(new RegExp('/events/([0-9*]+)/permalink/([0-9]+)'))

Returns array of 3 elements, 2nd item is event, 3rd item is permalink

'/*o*i*z*r*g/posts/3804270420760'
    .match(new RegExp('/([0-9a-z*]+)/posts/([0-9]+)'))

Returns array of 3 elements, 2nd item is user id, 3rd item is post id

Assuming the * won't be there, so you can drop it from the character ranges :)

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309