Getting Data In

How to filter out search results where a field value is with the string ?

Hemnaath
Motivator

Hi All,

We want to filter out the events based on a field value containing only the string characters, not the numerical values. How to do this using the search query.

index=test sourcetype=firewall | where NOT LIKE (service,"numerical") 

In service field, we could see both string characters and some port numbers, but we want to filter out only the event containing string characters, not with the port numbers.

Kindly guide me on this.

0 Karma
1 Solution

mayurr98
Super Champion

Try this run anywhere example

| makeresults 
| eval service="abc,23,sds,55,dffgdg,13,as,s,xyz"
| makemv service delim=","
| mvexpand service
| rex field=service "(?<service1>^((?!\d+).)*$)" | search service1=*

In your environment, you should try

index=test sourcetype=firewall | rex field=service "(?<service1>^((?!\d+).)*$)" | search service1=*

let me know if this helps!

View solution in original post

mayurr98
Super Champion

Try this run anywhere example

| makeresults 
| eval service="abc,23,sds,55,dffgdg,13,as,s,xyz"
| makemv service delim=","
| mvexpand service
| rex field=service "(?<service1>^((?!\d+).)*$)" | search service1=*

In your environment, you should try

index=test sourcetype=firewall | rex field=service "(?<service1>^((?!\d+).)*$)" | search service1=*

let me know if this helps!

Hemnaath
Motivator

HI mayurr98, thanks it helped me to fetch the result containing the field values=string characters.

hey i just done my regex course today, but still i am unable to figure out why the is placed like this in the group.

? quantifier syntax is used as optional
^ symbol is used to start with
?! syntax is the negative look head assertion - want to match something not followed by something else.
\d+ syntax is used for the numerical characters
. syntax is used a wild card
* quantifier syntax used zero or more of previous character
$ syntax used for end of the string.

thanks in advance

0 Karma

mayurr98
Super Champion

Well, this is my logic of extracting something.I did not find a direct way to extract string so what I did is I extracted non digit values(i.e. non numerical) so that is why I used ?! to negate numerical values
you can see my work here and you will find explanation as well on the right hand side.
https://regex101.com/r/qiZ6y3/1

Also,If you deem a posted answer as valid and helpful to your solving of the issue, please accept said answer so that this question no longer appears open.

0 Karma
*NEW* Splunk Love Promo!
Snag a $25 Visa Gift Card for Giving Your Review!

It's another Splunk Love Special! For a limited time, you can review one of our select Splunk products through Gartner Peer Insights and receive a $25 Visa gift card!

Review:





Or Learn More in Our Blog >>