0

Probably a minor one for the pros...

I want to detect a string of query parameters like:

var1=val1&var2=val2&...

I tried:

((.*)?(#[\w\-]+)?$&*)*

which is fine except it also matches

var1=val1&

which I don't want.


EDIT:

Tried also this:

(.*)=(.*)&*

is it a good solution?

1
  • Can you provide some examples of input data and expected results ? Commented Jul 16, 2019 at 9:12

2 Answers 2

1

Try this:

^([^=]+=[^&]*&)*([^=]+=[^&]*)$

Here, following matches one key-value pair.

[^=]+=[^&]*

So, zero or more key-value pairs each ending with &:

([^=]+=[^&]*&)*

And, one key-value pair at the end with no following &:

([^=]+=[^&]*)

Regex101

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

Comments

1

Try the following,

(?:&?[^=&]*=[^=&]*)+

You can test it from here as well as its description.


Tried also this:

(.*)=(.*)&*

is it a good solution?

No. What about the input string is something like var1=val1&var2=val2&...sdsad3423--**909 ?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.