Splunk Search

How to write the regex to extract numbers between two hyphens?

jhayIV
Engager

I have the following string 2016-02-17 field and I would like to extract the 02 between the hyphens. Does someone have a regex that will do this?

Tags (2)
0 Karma
1 Solution

vasildavid
Path Finder

Sure,

\d{4}-(?<month>\d{2})-\d{2}

Check out www.regex101.com It can help with building out/learning regular expressions.

View solution in original post

vasildavid
Path Finder

Sure,

\d{4}-(?<month>\d{2})-\d{2}

Check out www.regex101.com It can help with building out/learning regular expressions.

angelo_fazzina
Engager

is it this simple?

\-\d\d\-

\-  = escapes the 1st hyphen
\d\d  =  2 digits
\-  = escapes the 2nd hyphen

-ALF

0 Karma

jhayIV
Engager

Thank you so much I think I messed up the regex command in the search field
I entered the string below in the search field:

rex mode=sed"\d{4}-(?\d{2})-\d{2}"
0 Karma
Get Updates on the Splunk Community!

Splunk Answers Content Calendar, June Edition

Get ready for this week’s post dedicated to Splunk Dashboards! We're celebrating the power of community by ...

What You Read The Most: Splunk Lantern’s Most Popular Articles!

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...