Splunk Search

Proper REX command

tb5821
Communicator

What would the proper REX command be to extract the following:

SPACE:SPACE then a numeric string

so ends up being ' : 949495'

Tags (2)

amit_saxena
Communicator

Hi,

The regular expression rex "(?i)(?P<var> : [0-9]+)$" extracts space followed by a colon and then a space and then series of digits in the end of the line. If you just want to extract only the digit, then you should use the regular expression rex "(?i) : (?P<var>[0-9]+)$" .

Let me know if it works for you this time.

Note : Hopefully the characters in my regular expression should not get truncated.

Regards,
Amit Saxena

0 Karma

amit_saxena
Communicator

Hi,

Let me know if the my latest suggested solution to both the scenarios work for you.

Regards,
Amit Saxena

0 Karma

amit_saxena
Communicator

Hi

Putting the expression inside a code block.

rex "(?i)(?P<var> : [0-9]+)$"l

Hopefully this time, there are no characters that gets truncated

Let me know if it works for you

Regards,
Amit Saxena

amit_saxena
Communicator

The characters in my post are truncated. I will try to post my answer as reply to the post instead of the comment.

0 Karma

amit_saxena
Communicator

Hi,

rex "(?i)(?P : [0-9]+)$" will extract both the spaces including the colon character and then the digit. If you want to extract only the digit, then you should use rex "(?i) : (?P[0-9]+)$" .

Let me know if it works for you.

Note : Hopefully the character are not truncated from my regular expression while submitting the post.

Regards,
Amit Saxena

0 Karma

tb5821
Communicator

Still getting the ':'

var= : 8134038

0 Karma

amit_saxena
Communicator

Hi,

Let me know how following works for you.

rex "(?i)(?P<var> : [0-9]+)$"

Regards,
Amit Saxena

0 Karma

tb5821
Communicator

can you put it in a code block?

0 Karma

amit_saxena
Communicator

Still the characters in my post are getting truncated and I don't know why 😞

0 Karma

amit_saxena
Communicator

Let me know if this works.

rex "(?i)(?P : [0-9]+)$"

0 Karma

amit_saxena
Communicator

Hi,

Try the following regular expression.

rex "(?i)(?P<var> : [0-9]+)$"

Note : Please add "< var >" ( without spaces and quotes ) after "?P" in the regular expression. Due to some issue, the "<" and ">" characters are getting truncated from my post.

Regards,
Amit Saxena

0 Karma

amit_saxena
Communicator

Wait ! no matter I put correct answer, some characters are getting truncated when I submit the post ! I am posting the answer again in "post your answer" section.

0 Karma

amit_saxena
Communicator

Oh ! That was a typo from my side. Try the following and let me know the outcome.

rex "(?i)(?P : [0-9]+)$"

0 Karma

tb5821
Communicator

Error in 'rex' command: Encountered the following error while compiling the regex '(?i)(?P : [0-9]+)$': Regex: unrecognized character after (?P

0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

Any regex tutorial would have the regex. This one only extracts the digits.

your_search | rex field=_raw "\s:\s(?<extracted>\d+)"

0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

A better sample of data would help with the regex.

0 Karma

Ayn
Legend

It's basically what's in alacer's initial answer but you add the $ at the end. You may not know regex but reading through the answers and comments should give you some idea anyway.

0 Karma

tb5821
Communicator

Not sure how to do that and ensure it still matches on ' : 949495'

0 Karma

Ayn
Legend

If you don't want to include the string matched by \s:\s, just leave it out of the matching group.

0 Karma

Ayn
Legend

Which decimal?

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...