Splunk Search

Help with Regex to extract values

napoleon182
Explorer

Hello Splunk Ninjas!

I'm new to the group (and to the splunk) and will require your assistance with designing my regex expression.

I need to filter for the value of Message in this sample log line:

 

2022-09-23T13:20:25.765+01:00 [29] WARN  Core.ErrorResponse - {} - Error message being sent to user with Http Status code: BadRequest:
{"Message":"Sorry, only real values are valid in this environment.","UserMessage":null,"Code":64,"Explanation":null,"Resolution":null,"Category":3}

 

I will be interested in extracting value of Message, Code, Resolution and Category,

Any help, much appreciated!

Thanks again

Labels (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @napoleon182,

as you said, using the table command:

<your_search>
| rex "\{\"Message\":\"(?<Message>[^\"]+).*\"Code\":(?<Code>\d+),\"Explanation\":(?<Explanation>[^,]+),\"Resolution\":(?<Resolution>[^,]+),\"Category\":(?<Category>\d+)"
| table Message Code Explanation Resolution Category

Ciao.

Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @napoleon182,

this seems to be a json format, so you could use the spath command (https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/spath).

otherwise, you could use a regex like the following

| rex "\{\"Message\":\"(?<message>[^\"]+).*\"Code\":(?<Code>\d+),\"Explanation\":(?<Explanation>[^,]+),\"Resolution\":(?<Resolution>[^,]+),\"Category\":(?<Category>\d+)"

tha you can test at https://regex101.com/r/3YCPYQ/1

Ciao.

Giuseppe

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @napoleon182,

as you said, using the table command:

<your_search>
| rex "\{\"Message\":\"(?<Message>[^\"]+).*\"Code\":(?<Code>\d+),\"Explanation\":(?<Explanation>[^,]+),\"Resolution\":(?<Resolution>[^,]+),\"Category\":(?<Category>\d+)"
| table Message Code Explanation Resolution Category

Ciao.

Giuseppe

napoleon182
Explorer

Thank you Guiseppe, thats perfect, many thanks for your assistance!

0 Karma

napoleon182
Explorer

Thank you Giuseppe, how can i now present it in the table? (with using the | table switch)

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!

Monitoring AI Agents with Splunk Observability Cloud

Let’s say I’m running a travel planning AI app in production. A user asks for three concise hotel options in ...

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