Splunk Search

rex capture groups - windows file name and path

brdr
Contributor

I'm attempting to capture 2 groups; a windows path and filename. I've successfully written the rex syntax and it works using strong textregex101.com*strong text* app.

| makeresults
| eval test="C:\WINDOWS\TEMP\ABCDE\HELP_WITHREX_64.EXE"
| rex field=test "(?<Path>^.+\\)(?<File>[^\\]+\.\w+$)"
| table Path File

However, when I use in Splunk I get an error "Regex: missing terminating ] for character class." Any idea why? thx.

Tags (1)
0 Karma
1 Solution

xpac
SplunkTrust
SplunkTrust

Yeah, the | rex command is a little tricky, as stuff has to be double-escaped. Try replacing \\ with \\\ - that should work.
Hint: This is usually not necessary in config files, but in searches, as those have to be escaped once for the SPL parser and once for the regex parser.

Hope that helps - if it does I'd be happy if you would upvote/accept this answer, so others could profit from it. 🙂

View solution in original post

xpac
SplunkTrust
SplunkTrust

Yeah, the | rex command is a little tricky, as stuff has to be double-escaped. Try replacing \\ with \\\ - that should work.
Hint: This is usually not necessary in config files, but in searches, as those have to be escaped once for the SPL parser and once for the regex parser.

Hope that helps - if it does I'd be happy if you would upvote/accept this answer, so others could profit from it. 🙂

brdr
Contributor

Ah, thanks xpac...

This is the change, and now works.

 rex field=test "(?<Path>^.+\\\)(?<File>[^\\\]+\.\w+$)"
0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...