Splunk Search

Is there a syntax error in my search to extract a field from the source field?

HMTODD
Explorer

I am using the following search to extract a field, named 'JobName", from the field named "source"

index="nlg_test_csv_mfjobs" | rex field=source "SPLUNK\\(?[A-Z0-9]+)*_REPORT.*DETAILS.*\.CSV"

and I get this error:

Error in 'rex' command: Encountered the following error while compiling the regex 'SPLUNK\(?[A-Z0-9]+)*_REPORT.*DETAILS.*\.CSV': Regex: unmatched parentheses

I cannot find where the parenthesis are unmatched, unless they are being affected by the regular expression. The expression works in various online regex testers. I am concerned about some Splunk specific syntax that I may not be taking into account.

thanks.

0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

The right parenthesis needs to be escaped.

SPLUNK\(?[A-Z0-9]+\)*_REPORT.DETAILS..CSV

Depending on the data you are trying to match, one or more of the dots may need to be escaped as well.

---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

somesoni2
Revered Legend

Give this a try

index="nlg_test_csv_mfjobs" | rex field=source "SPLUNK\\\(?<JobName>[A-Z0-9]+)*_REPORT\.DETAILS\.CSV"
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The right parenthesis needs to be escaped.

SPLUNK\(?[A-Z0-9]+\)*_REPORT.DETAILS..CSV

Depending on the data you are trying to match, one or more of the dots may need to be escaped as well.

---
If this reply helps you, Karma would be appreciated.
0 Karma

HMTODD
Explorer

I am not a regx expert, but "guessed" that something was messing with the parenthesis (based on the error). Ultimately, this worked...

rex field=source "SPLUNK\(?[A-Z0-9]+)_REPORT.*DETAILS..CSV"

0 Karma

HMTODD
Explorer

Note that the string is being modified by the page after I submit. The string here is NOT correct. Let's try this. Note that the real search string does not have the outer quotes.

" rex field=source "SPLUNK\(?[A-Z0-9]+)_REPORT.*DETAILS..CSV" "

0 Karma

richgalloway
SplunkTrust
SplunkTrust

So parens are not literally in your events. Didn't guess that without sample data. The new regex doesn't work in regex101.com, BTW, but that's probably a markup problem. If you put your regexes inside back-tics it won't be messed with by the site.

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

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

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...