Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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
up vote 11 down vote accepted

How about this pattern:

(\?|\&)([^=]+)\=([^&]+)
share|improve this answer
3  
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
    
I know this is a little late but this answer will not ignore url fragments (anything after the "#"). Try this one: /[(\?|\&)]([^=]+)\=([^&#]+)/g – webwires Nov 12 '15 at 16:19
    
As in the RFC: tools.ietf.org/html/rfc3986#section-3.3 The semicolon(';') character can also be used to delimit parameters, So I think regex pattern should be changed accordingly – TMKasun May 27 at 12:49
[^&?]*?=[^&?]*

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.