Splunk Search

Why isn't this regex returning anything?

ashnet16
Path Finder

When running the regex below, the search doesn't return any results even though the reg ex string works well on the external regex builder I use. Help.

Here's the original string: \.(.{2,4}\s+?)

Here's the spunk search: index=*|fields file | rex field=file "(?\.(.{2,4}\s+?))" | stats count(Asset) AS "Total" by Asset | sort -Total

Tags (3)
0 Karma
1 Solution

musskopf
Builder

The first error is here:

(?.(.{2,4}s+?))

you have (? and ) at the start and end... that doesn't look right.

Also, to use the rex command, you need to use Named Capturing group in the regex, like:

.(?P<test>.+)

Where test will be the name of the field extracted.

View solution in original post

0 Karma

sves
Explorer

Hi ashnet16,

As Kristian says, we need some real data and also exactly what you try to extract from that data.

With that said, your original rex | rex field=file "(?\.(.{2,4}\s+?))" does not look right.

If you want to convert your original regular expression \.(.{2,4}\s+?) to rex, I would expect it to look something like this:

| rex field=file ".(?<fieldname>.{2,4}\s+?)"

Cheers!

#Sven Emil

0 Karma

ashnet16
Path Finder

This is the Splunk search Format for rex: (?...) (.....)equals the regular expression.

0 Karma

kristian_kolb
Ultra Champion

Hi,

please provide real data,
describe what you are trying to achieve,
use the code markup where appropriate, since this help with formatting and special characters

If you got a good answer, vote up a/o mark as answered.

/K

musskopf
Builder

The first error is here:

(?.(.{2,4}s+?))

you have (? and ) at the start and end... that doesn't look right.

Also, to use the rex command, you need to use Named Capturing group in the regex, like:

.(?P<test>.+)

Where test will be the name of the field extracted.

0 Karma

musskopf
Builder

Could you provide some of your RAW data? The content of field "file" should be enough.

0 Karma

ashnet16
Path Finder

Here is some raw data:

vcard.png
phone.png

style.css

jquery.colorbox-min.js

Thanks!!

0 Karma

musskopf
Builder

Ok, and is that a single line? or multiple entries? Also, what are you trying to extract?

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!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...