Splunk Search

How to check if a field only contains a -z and doesnt contain any other characters using rex?

ishugupta
Path Finder

How to check if a field only contains a-z and doesn't contain any other character using Rex.

Tags (1)
0 Karma
1 Solution

gkanapathy
Splunk Employee
Splunk Employee

The rex command doesn't check anything, it extracts fields from data. Even if you had a command that "checked", what do you want it to do? How you need Splunk to tell you, or what you you need Splunk to do on the basis of that information? Perhaps you need to look at eval http://docs.splunk.com/Documentation/Splunk/6.1.3/SearchReference/CommonEvalFunctions

View solution in original post

Runals
Motivator

What about

... | regex field_to_check="^[a-zA-Z]+$"

You mention breaking if those conditions aren't met but I'm wondering if you bake this into an append or join it would potentially be more useful. This approach would make the regex something like a where statement. Maybe something like

... | join type=left <join_field> [search blahblahblah | regex <join_field>="^[a-zA-Z]+$" | eval string_check = "woohoo I'm a string!" | table <join_field> string_check] | fillnull string_check value="I contain illegal characters" | table  <fields of interest> string_check

The advantage of this approach is that it doesn't totally break/stop the query if the field does contain numbers. If you take out the type=left in the join you will only move forward with values where there are matches at which point you might as well use the regex approach.

strive
Influencer

Try this and see if this is sufficient

Your Search... | eval FieldType = typeof(YOUR FIELD)
0 Karma

ishugupta
Path Finder

thanks..strive..

0 Karma

strive
Influencer

You cannot achieve this using rex. As gkanapathy mentioned use eval.

What you need is len, ltrim, tonumber functions

ishugupta
Path Finder

Thanks pablo... I simply need to put a condition on a variable ,to make sure that it only has characters.
I want to break my flow in case it contains null/numbers or spaces only.
For example my string is "This is a String"

gkanapathy
Splunk Employee
Splunk Employee

The rex command doesn't check anything, it extracts fields from data. Even if you had a command that "checked", what do you want it to do? How you need Splunk to tell you, or what you you need Splunk to do on the basis of that information? Perhaps you need to look at eval http://docs.splunk.com/Documentation/Splunk/6.1.3/SearchReference/CommonEvalFunctions

strive
Influencer

Splunk documentation says - Use the rex command for search-time field extraction or string replacement and character substitution.

Could you post your inputs and expected output.

0 Karma
Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...