Splunk Search

How to find field data that does not match expected output

vincenp2
New Member

I am collecting data from a field that should contain a 9 digit number.
I am finding that there are some instances where this field is blank, or contains alphanumeric characters

In order to quantify the issue (and identify this other content), could anyone advise what search query can I use to identify these events where the field does NOT contain a 9 digit number please ?

Tags (2)
0 Karma
1 Solution

micahkemp
Champion
rex field=your_field "^(?<expected_field>[0-9]{9})$" | search NOT expected_field=*

View solution in original post

micahkemp
Champion
rex field=your_field "^(?<expected_field>[0-9]{9})$" | search NOT expected_field=*

vincenp2
New Member

Thanks very much for this - it has provided me with a list of all events that do NOT contain a 9 digit number in the field, which is exactly what I wanted 🙂

0 Karma

mayurr98
Super Champion

hey @vincenp2

Try this run anywhere search

| makeresults | eval your_field="123456789" | rex field=your_field "(?P<field1>^\d{9})"    

your_field is the field that contains blank,9 digit and alphanumeric characters/numbers and field1 is the one with only 9 digit number which you can use for further analysis.

In your environment you should write

    <your_base_search>|  rex field=your_field "(?P<field1>^\d{9})"

chekc for field1 values which you can use in search query instead your_field

Let me know if this works!

0 Karma

vincenp2
New Member

Thanks for the input - it didn't quite produce what I was wanting - whether that was me getting it wrong somewhere or not I'm not sure - the accepted answer has provided the info I needed _ I don't know if from this you can get an understanding of the differences?

Thanks for replying though, much appreciated 🙂

0 Karma

mayurr98
Super Champion

hey this also gives same output just that you need to filter out events

 <your_base_search>|  rex field=your_field "(?P<field1>^\d{9})" | search NOT field1=*
0 Karma

micahkemp
Champion

I think the issue with your regex may be that it doesn't enforce that there are no additional characters after the nine digits.

0 Karma
Get Updates on the Splunk Community!

Splunk Observability Cloud’s AI Assistant in Action Series: Analyzing and ...

This is the second post in our Splunk Observability Cloud’s AI Assistant in Action series, in which we look at ...

Elevate Your Organization with Splunk’s Next Platform Evolution

 Thursday, July 10, 2025  |  11AM PDT / 2PM EDT Whether you're managing complex deployments or looking to ...

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