Splunk Search

How to edit my rex search to extract field values with a hyphen?

edrivera3
Builder

Hi

I am extracting a field named revision from raw data and the only possible field values are 1 or 2 consecutive upper case letters or a hyphen e.g.(A,B,AC,GF, -). I tried the following, but it didn't extract the field values with a hyphen:

 | rex field=_raw " Revision  (?[-A-Z]{1,2})" 
0 Karma
1 Solution

somesoni2
Revered Legend

Try this (assuming your data looks like this " some data Revision A" OR " some data Revision AB" OR " some data Revision -")

   your base search | rex " Revision\s+(?<Revision>[-A-Z]{1,2})

View solution in original post

somesoni2
Revered Legend

Try this (assuming your data looks like this " some data Revision A" OR " some data Revision AB" OR " some data Revision -")

   your base search | rex " Revision\s+(?<Revision>[-A-Z]{1,2})

edrivera3
Builder

That is what I did and it's correct. My error was that I didn't noticed that there is a space before the hyphen and the single upper case letter so I changed the regex and it worked. Thanks (I am going to accept your answer!)

| rex " Revision (?[A-Z]{2,2}|\s\W|\s[A-Z])" 

edrivera3
Builder

For some reason, it doesn't appear the angle bracket with the word "revision".

0 Karma
Get Updates on the Splunk Community!

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Shape the Future of Splunk: Join the Product Research Lab!

Join the Splunk Product Research Lab and connect with us in the Slack channel #product-research-lab to get ...