Splunk Search

Help with regex to extract a string?

Pramodkuber
Engager

Need to fetch API name from URL.
e.g. base_url/products_support/system_name/api-name?parameters

Here I need to fetch "system_name/api-name" string between "product_support" and "?".

Any inputs which regex needs to use here?

0 Karma

woodcock
Esteemed Legend

Like this:

| rex field=YourFieldHere "(?<base_url>[^\/?]+)\/(?<producst_support>[^\/?]+)\/(?<system_name>[^\/?]+)\/(?<api_name>[^\/?]+)?(?<parameters>.*)$"

Pramodkuber
Engager

Thanks a lot for your inputs. This is really very helpful. But I have few URLs where parameters are coming in path instead of queryparams.
How to take care of that? any idea?

e.g.
v2/customers/{customerID}/tickets
v2/customers/123456/tickets
v2/customers/987654/tickets

When I use "| stats values(api_name)" I am getting very big list as customer ID are different. I am looking result for 2/customers//tickets
"
" should take care of all dynamic values for customer Ids and " stats values(api_name)" sjoul return only one row for "v2/customers/*/tickets"

0 Karma
Get Updates on the Splunk Community!

The OpenTelemetry Certified Associate (OTCA) Exam

What’s this OTCA exam? The Linux Foundation offers the OpenTelemetry Certified Associate (OTCA) credential to ...

From Manual to Agentic: Level Up Your SOC at Cisco Live

Welcome to the Era of the Agentic SOC   Are you tired of being a manual alert responder? The security ...

Splunk Classroom Chronicles: Training Tales and Testimonials (Episode 4)

Welcome back to Splunk Classroom Chronicles, our ongoing series where we shine a light on what really happens ...