I have a scenario where i want to extract some substring based on following condition.
for ex:
The string is abcdmyvalue=123&xyz => the it should return myvalue=123
The string is abcdmyvalue=123 => the it should return myvalue=123
for first scenario it is working for me with following regex - myvalue=(.?(?=[&,""]))
I am looking for how to modify this regex to include my second scenario as well. I am using https://regex101.com/ to test this.
Thanks in Advace!
Some notes about the pattern that you tried
e*
matches 0+ times an e
char.*?(?=[&,""])
matches as least chars until it can assert eiter &
,
or "
to the right, so the positive lookahead expects a single char to the right to be presentYou could shorten the pattern to a match only, using a negated character class that matches 0+ times any character except a whitespace char or &
myvalue=[^&\s]*