Dashboards & Visualizations

How to match with rex if pattern can contain optional white spaces?

ctsurumaki
Explorer

 

I have a search query where the "# of Transactions Processed:" string sometimes contains one or more whitespaces before the numeric value but sometimes no whitespace

The below works fine for this example message 

| search message="# of Transactions Processed:51" 

| rex field=message "Processed:(?<ProcessedCount>\d+)"

 

But if the message has a space after the colon and before the number, then it doesn't match unless I add a space after the colon:

| search message="# of Transactions Processed: 51" 

| rex field=message "Processed: (?<ProcessedCount>\d+)"

 

Been struggling to find a good solution to this and was wondering if any of you Splunkers had figured this out previously 🙂   I could add another |rex with the second option but was hoping there was a more elegant and efficient way to accomplish it.

 

many thanks in advance !

 

Tags (2)
0 Karma
1 Solution

yeahnah
Motivator

Hi @ctsurumaki

try this...

| rex field=message "Processed:\s*(?<ProcessedCount>\d+)"

The \s* will match zero or more whitespaces.

Hope that helps

View solution in original post

yeahnah
Motivator

Hi @ctsurumaki

try this...

| rex field=message "Processed:\s*(?<ProcessedCount>\d+)"

The \s* will match zero or more whitespaces.

Hope that helps

Get Updates on the Splunk Community!

October Community Champions: A Shoutout to Our Contributors!

As October comes to a close, we want to take a moment to celebrate the people who make the Splunk Community ...

Community Content Calendar, November Edition

Welcome to the November edition of our Community Spotlight! Each month, we dive into the Splunk Community to ...

Stay Connected: Your Guide to November Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...