Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting all URL parameters using regex [duplicate]

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

like image 807
Mathew Kurian Avatar asked Feb 04 '13 00:02

Mathew Kurian


People also ask

How can I get multiple values from GET request URL?

Any word after the question mark (?) in a URL is considered to be a parameter which can hold values. The value for the corresponding parameter is given after the symbol "equals" (=). Multiple parameters can be passed through the URL by separating them with multiple "&".

What is a good regex to match a URL?

@:%_\+~#= , to match the domain/sub domain name.

How do I separate multiple query parameters in URL?

URL parameters are made of a key and a value, separated by an equal sign (=). Multiple parameters are each then separated by an ampersand (&).

How do you pass Queryparam?

Query parameters can be passed using the Router service or the queryParams directive. To access query parameters ActivatedRoute service needs to be used. Complex data types like arrays of objects can also be passed using query parameters however these data types need to be stringified before being passed.


2 Answers

How about this pattern:

(\?|\&)([^=]+)\=([^&]+)
like image 71
Sina Iravanian Avatar answered Oct 13 '22 06:10

Sina Iravanian


Try using this:

[^&?]*?=[^&?]*
like image 43
Kent Avatar answered Oct 13 '22 07:10

Kent