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 for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

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 ...