Splunk Search

Field regex behaves differently for "Field extractions" and for rex

frink
Explorer

I've got some log data that has a multi-line event this format:

2011-04-28 11:40:00|ACTION|1304005199906869|stuff|stuff|stuff

SPARAM|1304005199906869|PartNumber|1613034

SPARAM|1304005199906869|OtherParameter|8528

SPARAM|1304005199906869|OtherParameter2|true

I've created a regex to pull out the PartNumber field, and it seems to work perfectly when I run it through rex:

... | rex field=_raw "(?m)^SPARAM\|\d*\|PartNumber\|(?<SearchPartNumber>.*)"

Result: "1613034"

When I take the same regex and make it a saved Field extraction, I get the value I want plus everything else to the end of the event.

Result: "1613034

SPARAM|1304005199906869|OtherParameter|8528

SPARAM|1304005199906869|OtherParameter2|true"

I've tried adding an optional newline or end of line character to the end of the regex and it doesn't help.

Any thoughts on why this would behave differently and what I can do to fix it?

Thanks.

0 Karma
1 Solution

gkanapathy
Splunk Employee
Splunk Employee

The (?s) option defaults differently.

Use (?m-s)^SPARAM at the beginning, or else (?<SearchPartNumber>\V*) to prevent . from matching across line breaks.

View solution in original post

0 Karma

gkanapathy
Splunk Employee
Splunk Employee

The (?s) option defaults differently.

Use (?m-s)^SPARAM at the beginning, or else (?<SearchPartNumber>\V*) to prevent . from matching across line breaks.

0 Karma

frink
Explorer

Thanks so much for the prompt response. That fixed it!

0 Karma
Get Updates on the Splunk Community!

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 at Splunk .conf24 ...

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

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

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