Splunk Search

Rex Question

subtrakt
Contributor
rex "(?i)(?P<testERROR>(\:[^\:]*){2})$"

output

:test string 123:test test test123

I have to keep the the 2nd : match from the end of the line but i don't want it to be displayed in the output.

*when i say second match from the end, that means i would like to remove the colon from ":test"

Is this something where a lookahead/lookbehind is needed?

Tags (2)
0 Karma

woodcock
Esteemed Legend

If you are asking how to capture everything after the next-to-last colon (through the end of the line) but don't include the next-to-last colon, then do it like this:

... | rex ":(?<testERROR>[^:]*:[^:]*$)"

subtrakt
Contributor

I guess the quantifier wasn't needed. Thanks Woodcock!

0 Karma

woodcock
Esteemed Legend

If this worked, do click "Accept" to close the question.

0 Karma

diogofgm
SplunkTrust
SplunkTrust

is ":test string 123:test test test123" the string you want to use that regex?
if it is, you are capturing 2 groups

group "testERROR" - :test string 123:test test test123
unnamed group - :test test test123

what do you want to capture? this? "test test test123"

use https://regex101.com to test your regex

------------
Hope I was able to help you. If so, some karma would be appreciated.
0 Karma

subtrakt
Contributor

test string 123:test test test123
this is what i want to capture.

0 Karma

diogofgm
SplunkTrust
SplunkTrust

try this:

 ^:(?P<error>.*)$

if the complete string you're looking at is ":test string 123:test test test123" and you just want to remove the ":" this works.

------------
Hope I was able to help you. If so, some karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Upcoming Webinar: Unmasking Insider Threats with Slunk Enterprise Security’s UEBA

Join us on Wed, Dec 10. at 10AM PST / 1PM EST for a live webinar and demo with Splunk experts! Discover how ...

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...