First, I know my question would be possibly duplicate of this one, but I need solution which must be correct in 100%. And I am not so good in regexes to achieve this 🙂
I have maaaaaaaaany requests with few params passed like ...¶ms=key1=value1|key2=value2|.... There may be few params and I don’t know the order. What I need is to catch request that contains exact key1=myValue1 and key2=myValue2, but they can be like:
key1=myValue1|key2=myValue2key2=myValue2|key1=myValue1key1=myValue1|key3=myValue3|key2=myValue2
or even more complicated. What is known:
paramsis only part of the request, so it can be?something=other¶ms=key1=value1|key2=value2or?params=key1=value1|key2=value2&something=other- inside
paramsparameter there are not white chars, only pair(s) ofkey=value‘s (separated with|)
To be clear: I know two pairs of key=value so regex is only for matching requests containing those 2 pairs. Requests could be ordered in different way. I don’t have access to request itself, I only work on saved data (as string).
Language where regex will be used is PHP. But I don’t have access to full code, because we declare regex in web application interface.
I think I need two positive lookaheads, like (?=[^\s]*(key1=myValue1)[^\s]*){1}(?=[^\s]*(key2=myValue2)[^\s]*){1} but I can’t get it to work and clock is ticking…
Use two lookaheads:
The
\bword boundary anchors make sure that only entire alphanumeric “words” are matched.