Splunk Search

Rex extraction

redferrari
New Member

I have a field called "user", i'm trying to extract the username from the string and create a new field called extracted_user that I will later run against an LDAP filter to look up additional AD info.

user field examples:
Smith, John M. (jmsmith)(+)
Doe, Jane P. (jpdoe)(+)

I want to extract the username between the first set of parenthesis "jmsmith" and "jpdoe" respectively.

My current search:
index=network sourcetype=opsec app_rule_name="Track Uncategorized Content" user!=NULL
| rex field=user “((?.*))(“

Right now the search runs, but extracted_user field isn't created and the user field is unchanged. Any help would be greatly appreciated.

Tags (2)
0 Karma
1 Solution

cpetterborg
SplunkTrust
SplunkTrust

You need to escape the parentheses that are part of the string:

| rex field=user "\((?P<extracted_user>[^\(]+)\)\("

View solution in original post

gmchenry
Explorer

Try this:
| rex field=_raw "(?:()(?P\w+)"

I tested this at regex101.com and it seemed to do the trick.

0 Karma

cpetterborg
SplunkTrust
SplunkTrust

You need to escape the parentheses that are part of the string:

| rex field=user "\((?P<extracted_user>[^\(]+)\)\("

redferrari
New Member

Ohhh, thanks!

0 Karma

redferrari
New Member

| rex field=user “((?.*))(“

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...