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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...