Reputation: 4375
I am stuck on a regex for days now. I need to capture the values of key-value-pairs for specific keys. My data is like this:
key1 = "value1",
key2 = "value2",
key3 = "value3",
key4 = "value4"
I would like to capture the value of key2 and key4, there can be arbitrarily many key-values. It has to be done as a regex and is used in a tool called Splunk, which afaik does not support the /g modifier. This is how far I got:
(?:(?:key2 = "(.+)")|(?:key4 = "(.+)")) /g
(see http://regex101.com/r/yZ5tR9/1)
with the /g it works and captures "value2" and "value4", just like I want it, however, as said the /g is not available.
Any ideas how to capture two k/v-pairs without the modifier? Thanks a lot!
Upvotes: 0
Views: 1649
Reputation: 32202
Here's an update to your regex that works without the /g
modifier:
(?:(?:key1 = "(.+)")(?:.|\n)*?(?:key3 = "(.+)"))
The central non-capturing group just means match anything, including newlines, between the first key/value pair and the second key/value pair
Upvotes: 1