Splunk Search

Extract Last 12 Characters

IRHM73
Motivator

Hi, I wonder whether someone could help me please.

I have the following string, which I'm trying to extract the last 12 characters i.e. A1B-CDEFB-NOT

claim-a-token|N5Y-UWLB-NOT

I've tried using the following regex /|(?[^\s]+) but unfortunately it extracts the whole string and not just the last 12 characters, and I'm a little unclear why.

Could someone perhaps look at this please and offer some guidance on where I've gone wrong.

Many thanks

Chris

Tags (3)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi IRHM73,
if you haven't spaces in your string, this is your regex:

(?<field>[^ ]{12})$

if instead you have spaces in your string, you could use this regex:

(?<field>.{12})$

Bye.
Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi IRHM73,
if you haven't spaces in your string, this is your regex:

(?<field>[^ ]{12})$

if instead you have spaces in your string, you could use this regex:

(?<field>.{12})$

Bye.
Giuseppe

IRHM73
Motivator

Hi @cusello, thank you very much for this, it works great.

Many thanks and kind regards

Chris

0 Karma
Get Updates on the Splunk Community!

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

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