-1

I want to find the value corresponding to a specific key1 in QUERY_STRING using regex.

example :

"page?key1=value1&key2=value2&key3=value3"

"page?key2=value2&key1=value1&key3=value3"

"page?key2=value2&key3=value3&key1=value1"

I've found a regex like the one below, but it doesn't work the way I want it to in this situation.

key1=([^&]*)

"page?kkkkkkkey1=value1&key2=value2&key3=value3"

"page?key2=value2&kkkkkkey1=value1&key3=value3"

"page?key2=value2&key3=value3&kkkkkkey1=value1"
2
  • 2
    No, don't use regex. Use the appropriate URL parser of your language. Commented Jun 17, 2022 at 5:31
  • "it doesn't work the way I want it to in this situation" - what do you want then? Commented Jun 17, 2022 at 5:32

1 Answer 1

1

You could try

(\&|\?)key1=([^&]*)

This way the regex will match only if the the key1 is prepended by & or ?

Note: Now the value will be the second parenthesis match

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.