Splunk Search

Regex working in Regex101 and not Splunk

danielkhouri
Engager

Hello,

I've put together two Regex expressions to capture specific words from a syslog entry. First Regex is to capture the neighbor IP address (1.2.3.4) and the second Regex is to capture the vrf name (Test123). The intent is to use the values in a table.

<141>2019-09-13T16:33:48+00:00 HostABC %BGP-5-ADJCHANGE: neighbor 1.2.3.4 vpn vrf Test-123 Up

These are the Regex expressions I'm using that work in Regex101 and not in Splunk:

(?<=neighbor\s)(\S+)
(?<=vrf\s)(\S+)

Thanks.

Tags (1)
0 Karma
1 Solution

MuS
SplunkTrust
SplunkTrust

Hi danielkhouri,

You did not mention how you are using the regex in Splunk, but I suspect the opening < tag to be the problem.
You could try a simplified version of the regex and see if this works for you:

neighbor\s(?<my_ip>(\S+)) 
vrf\s(?<my_name>(\S+))

Using this in inline SPL using the rex command it will create the fields my_ip and my_name with the values 1.2.3.4 and Test-123 based on the provided sample.

Hope this helps ...

cheers, MuS

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi danielkhouri,
try this

(?<my_ip>\d+\.\d+\.\d+\.\d+).*vrf\s(?<my_vrf>[^ ]*\s+\w+$

Bye.
Giuseppe

0 Karma

MuS
SplunkTrust
SplunkTrust

Hi danielkhouri,

You did not mention how you are using the regex in Splunk, but I suspect the opening < tag to be the problem.
You could try a simplified version of the regex and see if this works for you:

neighbor\s(?<my_ip>(\S+)) 
vrf\s(?<my_name>(\S+))

Using this in inline SPL using the rex command it will create the fields my_ip and my_name with the values 1.2.3.4 and Test-123 based on the provided sample.

Hope this helps ...

cheers, MuS

0 Karma

danielkhouri
Engager

Hi MuS,

That worked - thanks for the information!

Another issue I have - I'm looking to create a Regex that capture 2019 Aug 21 01:00:25.971 AEST: and 2019 Aug 21 01:00:25.971 AEST: from the below:

2019 Aug 21 01:00:25.971 AEST: HostABC %BGP-5-ADJCHANGE: neighbor 1.2.3.4 vpn vrf Test-123 Up
2019 Aug 3 01:00:25.971 AEST: HostABC %BGP-5-ADJCHANGE: neighbor 1.2.3.4 vpn vrf Test-123 Up

I've configured the following expression (which works in Regex101) however I'm not getting any values in Splunk when I use it in a table

(?\d{4}\s\D{3}\s\d{2}\s\d{2}[:]\d{2}[:]\d{2}[.]\d{1,3}|\d{4}\s\D{3}\s\s\d{1}\s\d{2}[:]\d{2}[:]\d{2}[.]\d{1,3})

The thing to look out for is the extra space before the "3". Is there a better way of doing this?

0 Karma

MuS
SplunkTrust
SplunkTrust

Hi danielkhouri,

you did not mention how you will use the regex in Splunk - again. But since my first provided example worked for you I assume it is a inline SPL rex command. If so you will need to create a named capturing group https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Rex#Usage to tell Splunk to use the captured values in a field name.

Based on the provided examples try this:

(?<my_time>\d{4}[\d\s\w\.:]+AEST:)\s

Hope this helps ...

cheers, MuS

0 Karma

danielkhouri
Engager

Thanks again - that worked!

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

SOC4Kafka - New Kafka Connector Powered by OpenTelemetry

The new SOC4Kafka connector, built on OpenTelemetry, enables the collection of Kafka messages and forwards ...

Rounding off the Splunk Dashboard Contest

What does a contest-winning Splunk dashboard look like? In this case, it isn't in a browser tab at all. It ...