How to check if a field only contains a-z and doesn't contain any other character using Rex.
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
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.
Try this and see if this is sufficient
Your Search... | eval FieldType = typeof(YOUR FIELD)
thanks..strive..
You cannot achieve this using rex. As gkanapathy mentioned use eval.
What you need is len, ltrim, tonumber functions
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"
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
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.