1

I have a string where I'd like to extract some values with regex.

Whole string:

event=B:Rel&time=1511879856&date=20171128-143736&ref=57b3e1ab741d5a017ab8009033350b18&dir=out&src_if=GW1&dst_if=PRI1

I would like to isolate the values between the = and the next & creating this result set for the string given above.

B:Rel
1511879856
20171128-143736
57b3e1ab741d5a017ab8009033350b18
out
GW1
PRI1

Thanks for the help!

9
  • &?\w*=? Commented Nov 28, 2017 at 15:06
  • This way the matches would contain = and & You should try non-capturing groups: stackoverflow.com/questions/36619162/… Commented Nov 28, 2017 at 15:29
  • /(?:=)[a-zA-Z0-9-_%+]+(?:&)/g You can test on this site regex101.com Commented Nov 28, 2017 at 15:35
  • @ctwheels Beware of \w due to utf-8 there are Umlauts out there :-) Commented Nov 28, 2017 at 15:36
  • It seems to be a query string. What language are you using? Probably there is an easier way to do what you need. Also, why do you want those values in a single string? Commented Nov 28, 2017 at 15:39

2 Answers 2

2

Try this:

[^=]+=([^&]+)(?:&|$)

Regular expression visualization

DEMO: https://regex101.com/r/Z3pcR4/1

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

Comments

0

Depending on your language, you could split the input on this regex:

&?[^=]*=

Comments

Your Answer

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