I need to extract value of code from API response Header
This is the URL
Location : https://xxxx?code=MDXEVlThajoGXJj_-l6bYFaLxileF49d&state=8edf0d78`
I am using this Regular expression
Location: https://xxxx?code=([^"]+)\s
, but it is returning
code=MDXEVlThajoGXJj_-l6bYFaLxileF49d&state=8edf0d78
( whole value along with State) whereas I only want code=MDXEVlThajoGXJj_-l6bYFaLxileF49d
(State value is not required and should be truncated)
Let me know what am I missing here
You can exclude matching a whitespace char or an ampersand, and start the pattern with a word boundary to prevent a partial word match:
\bcode=([^\s&]+)&
See a regex demo.
Or if the ampersand is not mandatory:
\bcode=([^\s&]+)