Splunk Search

REGEX - how to mark end of value?

echojacques
Builder

So I have this REGEX statement in a transforms.conf file:

REGEX = (service=53|service=5101)

I'm new to REGEX but I believe this will match the service values of not only 53 or 5101 but also 535 or 5101555 etc. How do I modify this REGEX so it only matches on the exact values of 53 or 5101? Basically, put a stop after 53 and 5101?

Thanks.

Tags (1)
0 Karma
1 Solution

lukejadamec
Super Champion

Thanks, I just tried exactly what you posted...

REGEX = (service=53\||service=5101\|)

with 2 backslashes and it worked.Thanks!!

You're welcome.

View solution in original post

lukejadamec
Super Champion

Thanks, I just tried exactly what you posted...

REGEX = (service=53\||service=5101\|)

with 2 backslashes and it worked.Thanks!!

You're welcome.

echojacques
Builder

Thanks, I just tried exactly what you posted...

REGEX = (service=53\\||service=5101\\|)

with 2 backslashes and it worked.

Thanks!!

0 Karma

lukejadamec
Super Champion

I can understand your concern, because I have seen that happen. Have you tried including the |?
REGEX = (service=53\||service=5101\|)

0 Karma

echojacques
Builder

Service=5101:

loc=612777|time=21Aug2013 9:33:46|action=accept|orig=10.10.10.10|i/f_dir=inbound|i/f_name=eth1-03|has_accounting=0|rule_name=DC-Srv Internet Rule|service_id=Test922-Range|src=10.10.10.10|s_port=45606|dst=10.10.10.10|service=5101|proto=tcp|xlatesrc=10.10.10.10|xlatesport=39439|xlatedport=0|NAT_rulenum=244|NAT_addtnl_rulenum=1host=splk-01 Options|

sourcetype=opsec Options|

source=/data/splunk/etc/apps/Splunk_TA_opseclea_linux22/bin/lea-loggrabber.sh --configentity SplunkLEA Options|

service_id=Test922-Range Options|

service=5101 Options|

xlatesrc=10.10.10.10

0 Karma

echojacques
Builder

Well, there are 2 events (one contains service=53 and the other contains service=5101). And REGEX = (service=53|service=5101) actually works but I want to make sure that I'm not matching on service = 53XXX or 5101XXX etc. as well.

Sanitized events:

Service=53:

loc=561586|time=21Aug2013 9:30:16|action=accept|orig=10.10.10.10|i/f_dir=inbound|i/f_name=eth1-03|has_accounting=0|rule_name=DC-Srv Internet Rule|service_id=domain-udp|src=10.10.10.10|s_port=16478|dst=10.10.10.10|service=53|proto=udp|xlatesrc=10.10.10.10|xlatesport=59903|xlatedport=0|NAT_rulenum=244|NAT_addtnl_rulenum=1

0 Karma

lukejadamec
Super Champion

Can you post the event that contains what you want to extract?
The $ is actually 'end of line' not end of string (I think).

0 Karma

echojacques
Builder

I've tried that before and used the $ like this:

REGEX = (service=53$|service=5101$)

But this didn't work and actually stopped matching both 53 and 5101.

0 Karma

lukejadamec
Super Champion

The $ is used to mark the end of the value.

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 ...