Sign up ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

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

marked as duplicate by Bergi, Corbin, DocMax, Ram kiran, George Stocker Feb 4 '13 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.

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

2 Answers 2

up vote 9 down vote accepted

How about this pattern:

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

tested here

http://fiddle.re/bmdu

share|improve this answer
    
What about ; delimiter for query parameters? – alex Feb 4 '13 at 1:10
    
Doesn't work when I put it in rubular.com – Patrick Savalle Feb 18 '14 at 14:12

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