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!

Prove Your Splunk Prowess at .conf25—No Prereqs Required!

Your Next Big Security Credential: No Prerequisites Needed We know you’ve got the skills, and now, earning the ...

Splunk Observability Cloud's AI Assistant in Action Series: Observability as Code

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

Splunk Answers Content Calendar, July Edition I

Hello Community! Welcome to another month of Community Content Calendar series! For the month of July, we will ...