Splunk Search

Excluding a specific URL in Regex

SplunkNewbie18
New Member

Hi,

I read through forums on how to extract URLs using regex. But couldn't find those on how to exclude them.

For example, how do I extract all domain except for "google.com.sg".

Thanks!

Tags (1)
0 Karma
1 Solution

horsefez
Motivator

Hey,

so you particularely asked about removing it via the use of regular expression.
Let me give you an example:

google.com
google.com.sg
facebook.com
splunk.com
answers.splunk.com
idontknowanyurlsanymore.ru
iamahorseandilikeit.horse.me
factor.io

I've built a regular expression using a negative lookahead (?!...) to exclude the url from matching.
^(?!google\.com\.sg)(?<url>[^\n]+)(?:\n|)

https://regex101.com/r/wQ74EI/1

Let me know if you need additional help and/or explanation.

Cheers!

View solution in original post

0 Karma

horsefez
Motivator

Hey,

so you particularely asked about removing it via the use of regular expression.
Let me give you an example:

google.com
google.com.sg
facebook.com
splunk.com
answers.splunk.com
idontknowanyurlsanymore.ru
iamahorseandilikeit.horse.me
factor.io

I've built a regular expression using a negative lookahead (?!...) to exclude the url from matching.
^(?!google\.com\.sg)(?<url>[^\n]+)(?:\n|)

https://regex101.com/r/wQ74EI/1

Let me know if you need additional help and/or explanation.

Cheers!

0 Karma

SplunkNewbie18
New Member

Hi!

Yes, it works and this is what I wanted. Many thanks! 🙂

0 Karma

nickhills
Ultra Champion

If I understand what you want - you will still will need to extract the 'google.com.sg' url, but you may want to exclude it from your search.

You should be able to use != so assuming the extraction is called 'url':

<your existing search> url!=google.com.sg*|<etc..>
If my comment helps, please give it a thumbs up!
0 Karma

Sukisen1981
Champion

it will help if you can share your query wherein you are able to extract the url.
Also, what all urls do you want to exclude? Is it just one or do you have a list ?

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...