Splunk Search

How to edit regex for existing fields

jas0049
New Member

Hi!
need to edit existing fields using regex as its not giving proper values.
e.g. there is field called "IP" (auto extracted ) its have IP address with some other values. so need to remove extra values apart from ip address.
Please suggest.

0 Karma

woodcock
Esteemed Legend

The regex command is a search filtering command, not a field creating/parsing command. You need to use rex for that.

0 Karma

koshyk
Super Champion

Splunk can do it easily during search time. Please find regex for various IP address types

 | makeresults
 | eval mixedIP="10.0.0.1:8000"
 | rex field=mixedIP "(?<ipv4>(?:[0-9]{1,3}\.){3}[0-9]{1,3})"

..

0 Karma

cpetterborg
SplunkTrust
SplunkTrust

You can always use the rex command to create/modify a field that is always extracted. For example:

| makeresults
| eval IP="10.0.0.1:9997"
| rex field=IP "(?<myIP>[\d.]+)"

will result in myIP containing just the IP, and not the port from the IP field.

For future reference, it is always best to give some example data with your question so that it is easier to help answer you particular problem.

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!

Turn Cisco Telemetry Into Action with Cisco Data Fabric, powered by the Splunk ...

The surge in machine data is already hitting enterprise budgets, and the agentic era will only intensify it. ...

Automated Threat Analysis: Available in ES Premier

Automated Threat Analysis: Centralize and Accelerate Phishing Investigations in Splunk Enterprise ...

What’s New in Splunk AI: Volume 02

Welcome to the second edition of “What’s New in Splunk AI” where we look at the latest and greatest updates, ...