Splunk Search

Regex Working in Regex Tester But Not in Splunk

IRHM73
Motivator

Hi, I wonder whether someone may be able to help me please.

I've put together this regex which works perfectly in Regex101:

\"loggedInAt":\"(?<LoggedIn>[^\"]+)

This correctly extracts the 'loggedInAt' value from the raw data as shown below:

{"uri":"/auth/oid/4a1f00001b00002eb5","loggedInAt":"2015-10-18T18:30:34.976Z","credentials":{"gatewayId":"0000000"},"accounts":{"iht":{"link":"/iht/AA112456","nino":"AA111111A"},"sa":{"link":"/individual/12345678","ur":12345678"},"taxs":{"link":"/taxs/12345678","ur":"12345678"}},"lastUpdated":"2015-10-18T18:30:34.976Z","levelOfAssurance":"2","confidenceLevel":500}.

I then use this line in my Splunk query.

| rex field="detail.authority" ""\"loggedInAt":\"(?<LoggedIn>[^\"]+)"

The problem I have is that when I come to add "LoggedIn" to my table the relevant information is not being extracted and I'm nit sure why.

I just wondered whether someone could look a this please and let me know where I've gone wrong.

Many thanks and kind regards

Chris

Tags (2)
0 Karma
1 Solution

vincenteous
Communicator

Hi Chris,

I think I've found where your problem is. It's just the matter of placing the double quote character. Your rex was like this:

.. | rex field="detail.authority" ""\"loggedInAt":\"(?<LoggedIn>[^\"]+)"

I tried in my local environment using your sample data and it clearly was not working. So, I altered the rex into something like this:

.. | rex field="detail.authority" "\"loggedInAt\":\"(?<LoggedIn>[^\"]+)\""

The things I've tweaked are:

  1. Remove the first double quote
  2. Add backslash to the double quote after loggedInAt
  3. Add backslash to the last double quote and add another double quote at the end

This should solve your problem.

Best Regards

View solution in original post

0 Karma

vincenteous
Communicator

Hi Chris,

I think I've found where your problem is. It's just the matter of placing the double quote character. Your rex was like this:

.. | rex field="detail.authority" ""\"loggedInAt":\"(?<LoggedIn>[^\"]+)"

I tried in my local environment using your sample data and it clearly was not working. So, I altered the rex into something like this:

.. | rex field="detail.authority" "\"loggedInAt\":\"(?<LoggedIn>[^\"]+)\""

The things I've tweaked are:

  1. Remove the first double quote
  2. Add backslash to the double quote after loggedInAt
  3. Add backslash to the last double quote and add another double quote at the end

This should solve your problem.

Best Regards

0 Karma

IRHM73
Motivator

Hi @vincenteous, thank you very much for this it works a treat.

Kind Regards

Chris

0 Karma

dkoops
Path Finder

Splunk has some issues with double quotes inside double quotes, at least thats what I've experienced before. Therefore I always try to avoid using them in rexes. Try this one:

| rex "loggedInAt\W\:\W(?<VALUE>.*?)\W,"
0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...