Splunk Search

How can I escape the < > signs so that the token will properly hold my regex with these symbols?

jcorkey
Explorer

I am trying to set a token to have the following regex value rex "by (?<SU>[^(]+)". This regex is part of a larger search string.

This line of code <set token="searchstring">| rex "by (?<SU>[^(]+)"</set> almost works but it is having problems with the < > signs surrounding the SU in the regex. Because of the <SU> it gets an "unexpected close tag" error.

How can I escape the < > signs so that the token will properly hold my regex with these symbols?

0 Karma
1 Solution

sbbadri
Motivator

amp(&)gt; for>
amp(&)lt; for<

use ampersant symbol not string

View solution in original post

0 Karma

jkat54
SplunkTrust
SplunkTrust
 ...| rex "by (?<SU>[^(]+)\"\<\/set"

Try the backslash for escaping pcre special characters (as shown above)

0 Karma

sbbadri
Motivator

amp(&)gt; for>
amp(&)lt; for<

use ampersant symbol not string

0 Karma

jcorkey
Explorer

I am confused about how to use what you wrote. Can you show an example?

0 Karma

sbbadri
Motivator

i mean

ampersand_symbollt;suampersand_symbolgt;

0 Karma

jkat54
SplunkTrust
SplunkTrust
&lt; = <
&gt; = >
0 Karma

cpetterborg
SplunkTrust
SplunkTrust

Actually it looks like the </set> might be the problem, since it has no place in the rex command (outside the double quotes). If you have other code that didn't make it properly into the question, then I could certainly be wrong.

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...