Splunk Search

Rex match if else style

jeck11
Path Finder

Here are three lines of the file to illustrate what I'm going for:

Line from fileDesired field
URI : https://URL.net/tokentoken
URI : https://URL.net/rest/v1/checkrest/v1/check
URI : https://URL.net/service_name/3.0.0/accounts/bahservice_name


I have successfully extracted the 3rd example using this: 
rex field=_raw "URI.+\:\shttp.+\.(net|com)\/(?<URI_ABR>.+)\/\d+\."

That does not match the other two though so no field is extracted. Is there a way to say if it doesn't match that regex then capture till the end of line?

I've tried this but then the 3rd example also captures everything till the end of the line:
rex field=_raw "URI.+\:\shttp.+\.(net|com)\/(?<URI_ABR>.+)(\/\d+\.|\n)"



Labels (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The desired extractions are inconsistent.  The first two want everything after the domain, but the third wants only the first segment after the domain.  Please specify the rules for extracting URI_ABR.

---
If this reply helps you, Karma would be appreciated.
0 Karma

jeck11
Path Finder

Unfortunately, there are two different rules at play. One needs everything after the URL and the other only needs the URI which is a service name. That's what I've been struggling with.

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!

Laser Bananas and Edge Hubs: Exploring Operational Technology (OT) Data Through a ...

  OT is a different environment to traditional IT and can have interesting challenges when interfacing the ...

Event Series: Mastering AI Tokenomics and Splunk Agent Observability

Beyond the Black Box: Correlating AI Performance and Tokenomics with Splunk Agent Observability   As ...

span_metrics: The OpenTelemetry-Idiomatic Way to See Inside Your Services

You open a trace in Splunk Observability Cloud and everything looks fine. One root span, order-pipeline, with ...