Splunk Search

How to write the regex to extract URLs 32 to 48 characters in length and ending with .ru or .org?

avis1119
New Member

Hi Everyone,

I would like to write a regex for extracting URL's with 32 to 48 characters long and ending with .ru or .org..... there should not be any special characters involved before .org or .ru. Please help me in writing the regex

Thank you in advance.

0 Karma

aljohnson_splun
Splunk Employee
Splunk Employee

Hey @avis1119,

Whats good?

^(?<long_url>[\w\.-]{{32,48}(?=(?:\.org|\.ru)))

So this regular expression just gets a 32-48 character long string BEFORE a .org or a .ru. Its not very robust per se, it captures word characters (a-z, A-Z, 0-9, as well as a literal . and a dash and underscore). But if you were using it with rex in Splunk and had already defined a URL field, it should be fine, e.g.

| rex field=URL "^(?<long_url>[\w\.-]{32,48}(?=(?:\.org|\.ru)))"

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

0 Karma

avis1119
New Member

I have the field URL defined already.
it is not giving the exact output as i require... it should not include any spl characters even "." and "-" before TLD's. for example: hgwoui87864vhvbviobigb23Ajkbbjsgivu.org
eufvuUHOUVuw8y9814hviyiwh9283bhvcsdvg2tnbgbv.net

0 Karma

aljohnson_splun
Splunk Employee
Splunk Employee

just replace [\w\.-] with whatever you want like [a-z] for all lower case, [a-zA-Z] for lowercase and uppercase, [a-zA-Z0-9] for upper/lower/numbers.

0 Karma
Get Updates on the Splunk Community!

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...