Sunday 16 June 2019

javascript - Getting all URL parameters using regex












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


Answer



How about this pattern:



(\?|\&)([^=]+)\=([^&]+)

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...