Splunk Search

Regex generation

Deepz2612
Explorer

I have the below set of events where I wanted to write regex to capture only the last word

Kindly help

Tags (1)
0 Karma

woodcock
Esteemed Legend

Like this:

... | rex "(?<LastWord>\w+)$"
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi Deepz2612,
I don't see the set of events.
Anyway, to extract the last word od an event and put it in a field, you could use a regex like this:

| rex "\s+(?<my_field>\w+)$"

that you can test at https://regex101.com/r/hofrdl/1 .

Ciao.
Giuseppe

rmmiller
Contributor

Assuming you just want the last word in each event, this should work fine:

.+\b(\w+)$

If you want a more restrictive match, looking for only "begin" or "end", then this should work:

.+\b(begin|end)$

Hope that helps!
rmmiller

Edit: Used https://regexr.com/ to test/generate regex.

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...