I am trying to understand better how splunk regex works.
I have the below example:
This is a sample of the data I am trying to extract with
Slot No.=1 being of interest:
...,measObjLdn="SGSN02KPR/Process:Process No.=5, Process type=GBP, Slot No.=1,...
Using splunks Interactive field extractor gives me this
if I want to look at these values in the search I can do this
`... | rex "(?i)=.*?, (?P\w+\s+\w+.=\d+)(?=,)" | stats values(FIELDNAME)
Now to understand this better I would like to use an example. What if I just want the values so instead of getting
Slot No.=1 I would get
(?i)=.*?, (?P\w+\s+\w+\.=\d+)(?=,) would go to ...?
Appreciate any help and trying to understand this better, or is there any documentation on this.
For instance this
| rex ".*,.*Slot No.=(?P[^,]+)" will give me just the values this is just me playing around, I don't fully understand it.
Perhaps for you, its better to do a rex as follows, as you mentioned:
search.. | rex field=_raw "Slot No.\=(?<slot_number>[^,]+),"
This isnt a proper forum to learn regex, but this matches a "Slot No.=" string, and then uses a capture group for any thing that isnt a "," repeated infinite times till it finds a ",".
Key take away here is regex capture groups, and pattern matching.
Regex, or regular expressions, are not a idea in only in the world of Splunk. These are used throughout the development world and have been for years. I would recommend you study a bit on PCRE based patterns to get a better understanding of how regular expressions fit into the world of Splunk.
www.regex101.com is quite a valuable resource, not to mention others out there..
tks but would you help me understand and break this down?
have to rewrite the above as everything between
> symbols disappears, but not if i use
< = <
> = >
< = <
> = >
You can learn regex as you go I believe, you only really need help in truly complicated cases. What helps a lot is a tool like regex101 where you can try your expression on your sample data and which highlights your syntax graphically, explains your regex step for step and also has a quick reference of frequently used commands at hand - it's really great!
If you DO post regex code here, please keep in mind to post it as code - not with grave accents, but with an empty row before it and indented by four spaces. That will preserve any special characters such as angular brackets, which, as you can see, are lost in the question you posted.
Below posted using the code button above (
Below posted using grave accents - Note the difference
Just thought you might find this useful, but here's a previous answers post where a handful of users on Answers shared their favorite online (and 1 offline) regex resources. One of them has exercises for practice and better understanding.