Getting Data In

How to create regex formula to match all until 3 or more spaces?

bosseres
Contributor

Hello everyone, I have such fields in log:

event="some text text2 text3   something     something2", how should I make regex formula to match all until 3 or more spaces? for example, for this event it should match "some text text2 text3"

Labels (2)
Tags (1)
0 Karma
1 Solution

jamie00171
Communicator

@bosseres Sorry, I tested it like:

jamie00171_0-1674557176995.png


because I assumed the actual _raw field / event in Splunk would start like: 

"some text text text something something"

is that not correct? thanks

 

View solution in original post

jamie00171
Communicator

Hi @bosseres,

 

This will match everything from the start of the event until there are 3 or more spaces:

| rex field=_raw "^(?<description>.+?)\s{3,}"

 

Thanks,

 

Jamie

bosseres
Contributor

tried so, but..

bosseres_0-1674556331414.png

 

0 Karma

jamie00171
Communicator

@bosseres Sorry, I tested it like:

jamie00171_0-1674557176995.png


because I assumed the actual _raw field / event in Splunk would start like: 

"some text text text something something"

is that not correct? thanks

 

bosseres
Contributor

my raw event in splunk looks like field1="223" field2="333" event="some text text2 text3 something something2"

can you add to this regular formula part, which whill parse field event? 

I mean event="..."

bosseres_0-1674558819256.png

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
^\S*\s\S*\s\S*\s\S*

bosseres
Contributor

hm, not working description="(?<description>^\S*\s\S*\s\S*\s\S*") - something wrong?

more, I dont know how many words will be before spaces, I must match all of them

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Your requirement is ambiguous. Do you want to include the spaces between words in your count of "three spaces"? Or do you want everything before three consecutive spaces? Also, the carat is in the wrong place when you have put it in an expression, try it this way

"^(?<description>\S*\s\S*\s\S*\s\S*)"

bosseres
Contributor

I want everything before three consecutive spaces, but regular still dont work

bosseres_0-1674556175831.png

 

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
"description=\"(?<description>.*?)\s{3}"
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...