Splunk Search

How do I skip words in a field extraction?

aohls
Contributor

I am working two extract fields and I have the following two lines:

"ActionName processing for AccountName completed"
"ActionName processing for account: AccountName completed"

I want to extract ActionName and AccountName as new fields using the field extractor. I am writing the expression myself and was doing something like the following:

"(?<ActionName>\w+) processing for (?<AccountName>\w+) completed"

In doing this though, I am missing the second event, "ActionName processing for account: AccountName completed". Is there a way I can have my expression run for both events correctly? I want to run with an unknown amount of space between the two and wanted to avoid doing two extractions.

I am writing the expression myself since the other way does not work correctly either.

0 Karma
1 Solution

aholzer
Motivator

This should do it:

"(?<ActionName>\w+) processing for (account:\s)?(?<AccountName>\w+) completed"

The (account:\s)? portion means that the string "account: " can appear 0 or 1 times (or in plain English, that it's optional).

Hope this helps.

View solution in original post

0 Karma

aholzer
Motivator

This should do it:

"(?<ActionName>\w+) processing for (account:\s)?(?<AccountName>\w+) completed"

The (account:\s)? portion means that the string "account: " can appear 0 or 1 times (or in plain English, that it's optional).

Hope this helps.

0 Karma

aohls
Contributor

This is exactly what I was looking for. Thank you!

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

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