Splunk Search

Why does regex keeps extracting wrong data?

jhilton90
Path Finder

I am trying to use the rex command to extract an id number, which is a mixture of letters and numbers separated by a dash. For example, one of the ids looks like this:

34gv564-3333-5tg4-gt53-4rgt5eg5g35gb

The field itself is as follows: MFA challenge succeeded for account aaaaaaaaa with email example@example.co.uk. Session id is 34gv564-3333-5tg4-gt53-4rgt5eg5g35gb

The rex command I'm using is as follows:

 

| rex "(?i) is (?<id_number>[^\"]+)"

 

The only problem is that sometimes it extracts the email address bit too

Any help would be greatly appreciated

Labels (3)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

To avoid extracting data from the wrong place, the regex should be more specific.

| rex "Session id is (?<id_number>[^\"]+)"

Since we only have a partial event to work with (the regex implies something in quotes follows, but it's not in the example event), it's impossible to know if there is a better way to extract the field.

---
If this reply helps you, Karma would be appreciated.
0 Karma

karu0711
Communicator

try this

| rex ^(?<id_number>.+)

0 Karma

jhilton90
Path Finder

That just extracts the entire event unfortunately

Thanks anyway though

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: Tiling

This puzzle (first published here) is based on finding groups of tessellated tiles (inspired by floor tiles I ...

SOK it to Me: Top 3 Benefits of Using Splunk Operator on Kubernetes that’ll Make ...

    Thursday, July 9, 2026  |  11:00AM–12:00PM PDT Duration: 1 hour (includes Q&A) Managing can feel like a ...

Upgrade Prep for 10.4, Network Observability Deep Dives, and More from Splunk Lantern

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...