Splunk Search

Regular Expression for field extraction

brennson90
Path Finder

Hi everyone,

i got two URLs which i want to represent in one regex group. The dest Port (443) will be in a seperate group

Here are two examples.



my.url.is.here:443

http://myurl.de/tasks/search/home?

 

When i use the following regex "(?<url>[^\s:]+):?" the first example is fine, but the second only catches "http" because it only matches till the ":"

Can someone help and fix my regex?

Thanks.

Labels (2)
0 Karma
1 Solution

brennson90
Path Finder

Hi, i found the solution "(?<url>.+)(:|\?)"

Anyways, thanks for the support @ITWhisperer 

View solution in original post

0 Karma

brennson90
Path Finder

Hi, i found the solution "(?<url>.+)(:|\?)"

Anyways, thanks for the support @ITWhisperer 

0 Karma

brennson90
Path Finder

Hi @ITWhisperer thx for the reply. Now the first number of the dest port is lost.

It captures everything till "my.url.is.here:4"

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Please provide the SPL you are using (in a code </> block preferably)

0 Karma

brennson90
Path Finder

I'm not 100% sure what you want to see.

This is my search

index=mysearch
|  rex "\s(?<url>.+)(:\d|\?)(?<dest_port>\d+)?\s+"

 

 

Tags (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

If you don't mind losing the ?, you could use

"(?<url>.+)(:\d|\?)"
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...