Splunk Search

Regex fails as when defined as field extraction, but works with rex command. "Regex: missing terminating ] for character class"

neiljpeterson
Communicator

This works in my search:

rex field=source "\w:\\\[\w]*\\\(?<app_path>[^\\\]*)"

But when I try to define it as a field extraction I get the following error:

Encountered the following error while
trying to save: In handler
'props-extract': Regex: missing
terminating ] for character class

All the parens are clearly balanced... what is going on here?

0 Karma

gkanapathy
Splunk Employee
Splunk Employee

In the rex command, you need an extra level of escaping of the string (much like you need an extra level of escaping of characters when you specify regexes on the bash command line). But when you define a field extraction in props directly, you need to just specify the regex without the outer layer of escaping. So your base regex should be simply:

\w:\\[\w]*\\(?<app_path>[^\\]*)

Assuming you're trying to get my_app out of something like c:\base\my_app\whatever\file.txt

sk314
Builder
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...