Splunk Search

REGEX in transform.conf using "^" to specify the begining does not work

aferchichi
New Member

Hi,

I specified the following in transforms.conf

SOURCE_KEY = MetaData:Host
REGEX = ^8\.\d{1,3}\.\d{1,3}\.\d{1,3}$
DEST_KEY = _MetaData:Index
FORMAT = special_index

This should noramlly match host like 8.23.15.12, but it does not work. And if a remove the "^" it will match but it will also match 18.23.15.12 which I do not want. It seems that the "beging with" is not working... Is this a bug? is there a way to circumvent it?
Thanks for your help,

Azim

0 Karma

nunoaragao
Path Finder

Maybe not working because SOURCE_KEY = MetaData:Host will return

host::

at the begging of the string.
Maybe change REGEX to either

REGEX = ^host\:\:8\.\d{1,3}\.\d{1,3}\.\d{1,3}
REGEX = (?<!\d)8\.\d{1,3}\.\d{1,3}\.\d{1,3}

 

0 Karma

aferchichi
New Member

Thanks
but it does not work neither...

Any other suggestions?

Azim

0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

You could try this REGEX:

^8\.\d{1,3}\.\d{1,3}\.\d{1,3}

Dropping the $ might help, since you don't really care about the end of the string, just the beginning.

0 Karma

sowings
Splunk Employee
Splunk Employee

Some of the other metadata fields have a hidden prefix of the name of the field itself, so it could be host::8.x.y.z

0 Karma

aferchichi
New Member

In fact, I think the Host variable extracted has some non viewable characters before the digits (maybe a space), that's why it did not match the "begin with 8" expression ^8.

0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

I checked that regex here: http://gskinner.com/RegExr/, with these IPs:

128.3.2.4
8.4.3.2
18.3.4.5

And it only matches the 8.4.3.2 IP.

0 Karma

aferchichi
New Member

Thanks again... But here you must have something before the number "8", like a8.4.5.7 and therefore will not match the 8.4.5.7

0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

[^0-9]{1,2}[^0-79]{1}\.\d{1,3}\.\d{1,3}\.\d{1,3} . Not sure why it's not picking up the "^".

0 Karma

aferchichi
New Member

Thanks but it leads to the same result... Your expression will also match 18.2.3.4 ... Which I dont want. It really seams that splunk is not capable of interpreting the begining of a string "^".

0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

[^0-79]{1}\.\d{1,3}\.\d{1,3}\.\d{1,3} ?

0 Karma

aferchichi
New Member

Thanks
but it does not work neither...

Any other suggestions?

Azim

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!

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...