Splunk Enterprise

What regex can extract everything up to a specific character?

Steve_A200
Path Finder

Hi,

I need assistance with writing a regex that extracts all characters upto the character "_" underscore.

so, the data could look like this:

field1:

ABCD_1234234
EFG_12349879
HIJK_12349850

And I would like to only see:

ABCD
EFG
HIJK

I tired this however it is not doing the trick:


| regex field1 = "^.*?(?=\_)"

regex101 seems to show it working but ... I must be missing something when converting it into splunk.

Any help would be appreciated.

Thanks,

Labels (2)
0 Karma
1 Solution

abi2023
Path Finder

basesearch | rex field=field1 "^(?<field2>[^_]+)_" 

View solution in original post

abi2023
Path Finder

basesearch | rex field=field1 "^(?<field2>[^_]+)_" 

Steve_A200
Path Finder

Thank you, that worked exactly how I needed it to work.

0 Karma
Get Updates on the Splunk Community!

Splunk Observability Cloud's AI Assistant in Action Series: Auditing Compliance and ...

This is the third post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

What You Read The Most: Splunk Lantern’s Most Popular Articles!

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...