Splunk Search

Can we have a dash in the generated rex field name?

danielbb
Motivator

The following works just fine -

 | makeresults 
 | eval temp="IP-Group={xxxx} {yyyy} {zzz}" 
 | rex field=temp max_match=0 "\{(?P<result>[^}]+)"

But the following breaks -

 | makeresults 
 | eval temp="IP-Group={xxxx} {yyyy} {zzz}" 
 | rex field=temp max_match=0 "\{(?P<re-sult>[^}]+)"

Saying - Error in 'rex' command: Encountered the following error while compiling the regex '\{(?P<re-sult>[^}]+)': Regex: syntax error in subpattern name (missing terminator).

Adding the dash, making it re-sult, broke it. Is there a way around it?

regex101 doesn't like it either...

Tags (1)
0 Karma
1 Solution

dindu
Contributor

Hi Daniel,

Splunk has some restriction on naming field names.
This limits us from having a hyphen .

Please read on the below.

https://docs.splunk.com/Documentation/Splunk/7.3.1/Data/Configureindex-timefieldextraction.

Field name syntax restrictions
You can assign field names as follows:

Valid characters for field names are a-z, A-Z, 0-9, or _ .
Field names cannot begin with 0-9 or _ . Splunk reserves leading underscores for its internal variables.
Avoid assigning field names that match any of the default field names.

Do not assign field names that contain international characters.

However, we could use an eval command to generate a field with hyphen.
Eval operates only at the search time. Please test and let us know

| makeresults 
| eval temp="IP-Group={xxxx} {yyyy} {zzz}" 
| rex field=temp max_match=0 "\{(?P<result>[^}]+)"
|eval re-sult=result

View solution in original post

dindu
Contributor

Hi Daniel,

Splunk has some restriction on naming field names.
This limits us from having a hyphen .

Please read on the below.

https://docs.splunk.com/Documentation/Splunk/7.3.1/Data/Configureindex-timefieldextraction.

Field name syntax restrictions
You can assign field names as follows:

Valid characters for field names are a-z, A-Z, 0-9, or _ .
Field names cannot begin with 0-9 or _ . Splunk reserves leading underscores for its internal variables.
Avoid assigning field names that match any of the default field names.

Do not assign field names that contain international characters.

However, we could use an eval command to generate a field with hyphen.
Eval operates only at the search time. Please test and let us know

| makeresults 
| eval temp="IP-Group={xxxx} {yyyy} {zzz}" 
| rex field=temp max_match=0 "\{(?P<result>[^}]+)"
|eval re-sult=result

danielbb
Motivator

@dindu - |eval re-sult=result works like a charm.

It would be nice to know why "\{(?P<re-sult>[^}]+)" breaks even at the regex level.

0 Karma

dindu
Contributor

Hi Daniel,

The field extracted is shown in the list of fields on the sidebar which implies the naming should satisfy the condition.
Whereas the eval is just happening on the front end Splunk UI.

Please accept if this helped.

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 ...