Hi community,
I'm using rex to get some strings.
The log is like
\"submission_id\":337901
The regex I'm using is:
\"submission_id\\\":(?<subID>\d+)
It works well on regex101:
https://regex101.com/r/Usr7Ki/1
However, in Splunk, it doesn't find anything.
The command is (just added double quotes to wrap the regex)
rex "\"submission_id\\\":(?<subID>\d+)"
Any ideas and suggestions are appreciated!
You need to double up on some of your backslashes
| rex "\\\"submission_id\\\\\":(?<subID>\d+)"
Essentially, the rex command goes through a extra step of string parsing so backslashes have to be escaped an extra time
Hi @syk19567,
it's a bug that I requested to solve for one of our biggest customers:
if you tested a regex containing a backslas in regex101 and it runs, to use this regex in a search you have to add other two backslashes to each backslash.
If instead you want to use this regex in a field extraction, you have to use the regex from regex1010 (the one with one backslash).
so the regex to use in a search is:
| rex "\\\\\"submission_id\\\\\":(?<submission_id>\d+)"
instead the regex to use in the extract field (and regex101) is
\\\"submission_id\\\":(?P<submission_id>\d+)
In addition, if you try to use the IFX on the same sourcetype, you have an error and you cannot use IFX.
As I said, I asked to solve this bug but they didn't give me a date.
Ciao.
Giuseppe
Thank you Giuseppe, this is very informative!
You need to double up on some of your backslashes
| rex "\\\"submission_id\\\\\":(?<subID>\d+)"
Essentially, the rex command goes through a extra step of string parsing so backslashes have to be escaped an extra time
This blows my mind and I'm kinda lost. But this really works!! Thank you!