Splunk Search

help in a regular expression extraction

royimad
Builder

I have a text that contains anything followed by a word that start with either
XPOS, POS and HF and ended by -

Example:
ABC XPOS2024 -
DEF POS340903 -
GHI HF3948329 -
...

How to extract XPOS2024 , POS340903 , HF3948329 using regular expression?

Tags (3)
0 Karma

dishasaxena
Path Finder

You may try below regex as well:
"(?:)[^ ]+ +(?P(XPOS|POS|HF)[^ ]+) +-"

If it does not work please let me know.

Regards,
Disha

royimad
Builder

Thanks man

0 Karma

yannK
Splunk Employee
Splunk Employee

try this on the search : (and remove the underscored, they are here to trick the html formatting)


* | rex "(?<myfield>(XPOS|POS|HF)\d+)" | table myfield

royimad
Builder

It's working great thank you guys

0 Karma

yannK
Splunk Employee
Splunk Employee

Thanks Åynm I had a missing parenthesis.

And if the characters after are not always digits, disha's regex is perfect.

0 Karma

Ayn
Legend

* | rex "(?<myfield>(XPOS|POS|HF)\d+)" | table myfield

royimad
Builder

it seems that this isn't working

0 Karma

royimad
Builder

I'm receiving this error

0 Karma

royimad
Builder

Error in 'rex' command: Encountered the following error while compiling the regex '?(XPOS|POS|HF)\d+)': Regex: nothing to repeat

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...