Splunk Search

Regex sanity check - fixed record length field extraction

himynamesdave
Contributor

Guys, I have a horrible dataset in Splunk and am trying to match fields based on a position in event.

As an example, I need to extract a field which is found in the 201st and 202nd position of the event. I tried the following extraction (with some iteration) which fails.

| rex (.){200}(?P<FIELD>.{2})

What should it look like?

Thanks!

Tags (2)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Remove the parentheses from around the first dot and it should work. Of course, the whole regex string must be quoted.

 | rex ".{200}(?P<FIELD>.{2})" | ...
---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

Remove the parentheses from around the first dot and it should work. Of course, the whole regex string must be quoted.

 | rex ".{200}(?P<FIELD>.{2})" | ...
---
If this reply helps you, Karma would be appreciated.

jacobwilkins
Communicator

Also, anchor it.

| rex "^.{200}(?P<FIELD>.{2})"

himynamesdave
Contributor

Thanks guys!

0 Karma
Get Updates on the Splunk Community!

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

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 ...