Grok pattern with regex


#1

Hi,

I am trying to match a string using a grok pattern with regex.
An example string is:
(1) 12.3 abc Chrome/4.56 OPR/7.89
In this case I want my regex to match OPR.
In case the string looks like this:
(2) 12.3 abc Chrome/4.56/7.89
I want my regex to match with Chrome.
So, I want OPR to have precedence over Chrome.

If I simply use the regex (OPR) then it matches OPR.
However, when I use the regex: (OPR)|(Chrome) it always matches Chrome (also in string (1)). I have also tested with other substrings (for example abc) in this regex and it seems to be matching the substring that occurs first in the entire string.

I read that in a regex the first match in the regex wins, so that would mean OPR would match. However, since this is not the case I am wondering what I am doing wrong. Can someone help me with this?
Thank you in advance.


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.