Getting Data In

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

bosseres
Communicator

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
Communicator

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
Communicator

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
Communicator

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
Communicator

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!

New Splunk Observability innovations: Deeper visibility and smarter alerting to ...

You asked, we delivered. Splunk Observability Cloud has several new innovations giving you deeper visibility ...

Synthetic Monitoring: Not your Grandma’s Polyester! Tech Talk: DevOps Edition

Register today and join TekStream on Tuesday, February 28 at 11am PT/2pm ET for a demonstration of Splunk ...

Instrumenting Java Websocket Messaging

Instrumenting Java Websocket MessagingThis article is a code-based discussion of passing OpenTelemetry trace ...