-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!

2
  • duplicate of stackoverflow.com/questions/6644654/… Commented May 29, 2012 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. Commented May 29, 2012 at 15:44

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

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 :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.