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!

Building Reliable Asset and Identity Frameworks in Splunk ES

 Accurate asset and identity resolution is the backbone of security operations. Without it, alerts are ...

Cloud Monitoring Console - Unlocking Greater Visibility in SVC Usage Reporting

For Splunk Cloud customers, understanding and optimizing Splunk Virtual Compute (SVC) usage and resource ...

Automatic Discovery Part 3: Practical Use Cases

If you’ve enabled Automatic Discovery in your install of the Splunk Distribution of the OpenTelemetry ...