Splunk Search

Why is the following regex expression not matching as expected?

SunilMaharishi
Path Finder

I have a field user= xyz\user11 and i need to match user11 ignoring xyz in the user filed

below is the regex expression we have been trying but it gives error as unmatched parenthesis or some other and Result field is not available in the logs if it runs successfully .

rex field=user (?\w+\\(\w+))
Tags (2)
0 Karma
1 Solution

pjnike
Engager

You have to specify which field to extract the value to. Also, the backslash(\) before opening parenthesis in your query escapes the ( which causes Splunk to give an error of unmatched parenthesis. You need to escape the backslash with \.

Try this: rex field=user "\w+\\\(?<user_name>\w+)"

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

We can't read your rex string because the forum mangled it. To prevent this, put code, HTML, and SPL inside backticks or use the code button (101010).

Backslashes require extra escape characters in regex strings within SPL. Try rex field=user "\\\(?<Result>.*)".

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

pjnike
Engager

You have to specify which field to extract the value to. Also, the backslash(\) before opening parenthesis in your query escapes the ( which causes Splunk to give an error of unmatched parenthesis. You need to escape the backslash with \.

Try this: rex field=user "\w+\\\(?<user_name>\w+)"

0 Karma

SunilMaharishi
Path Finder

that was mistyped fieldname was specified though

but it is working now thank you

0 Karma
Get Updates on the Splunk Community!

Splunk Enterprise Security(ES) 7.3 is approaching the end of support. Get ready for ...

Hi friends!    At Splunk, your product success is our top priority. With Enterprise Security (ES), we're here ...

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

Watch On Demand the Tech Talk, and empower your SOC to reach new heights! Duration: 1 hour  Prepare to ...

Splunk Observability for AI

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