Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Possible Duplicate:
How can I get query string values?

Trying to get a regex (Javascript).

Input:   url.html?id=14114&yolo=hahaha
Output:  id=14114
         yolo=hahaha

So this is what i have done so far: (\&|\?)(.*?)\=(.*?)

How do I also include the red circled regions?

enter image description here

share|improve this question
1  
Do you mean url.html?id=14114&yolo=hahaha? – alex Feb 4 at 0:55
Yes I did. thanks for that. – mk1 Feb 4 at 0:57
Why does it need to be regex? – Bergi Feb 4 at 0:59
@alex:I updated the question. – mk1 Feb 4 at 1:00

marked as duplicate by Bergi, Corbin, DocMax, Ram kiran, George Stocker Feb 4 at 3:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

up vote 1 down vote accepted

How about this pattern:

(\?|\&)([^=]+)\=([^&]+)
share|improve this answer
1  
Why is & escaped? – alex Feb 4 at 1:02
1  
I made a change after he posted. with his help: (\?|\&)([^=]+)\=([^\&]+) – mk1 Feb 4 at 1:02
Updated, thanks. – Sina Iravanian Feb 4 at 1:04
[^&?]*?=[^&?]*

tested here

http://fiddle.re/bmdu

share|improve this answer
What about ; delimiter for query parameters? – alex Feb 4 at 1:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.