Splunk Search

What rex to use for the extraction of virtual from URI?

lbonnes
Observer

These two cells are examples of results I see in IIs logs. 

If the field is just a / (backslash) ( as in the first example data cell ) I want to return just the /. 

If there are characters after the first / (like search in #2) , I need to return the text between the backslashes.  

/
/search/20191108/master.svc

 

My results would look like this. 

field1

root   

search

Labels (2)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

This should do it.

| rex "\/(?<field1>[^\/]+)"
| eval field1=if(isnull(field1) OR field1="","root", field1)

  The rex command grabs everything between the first two slashes.  The eval command presumes a missing or empty field1 means the root was specified. 

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Splunk Decoded: Service Maps vs Service Analyzer Tree View vs Flow Maps

It’s Monday morning, and your phone is buzzing with alert escalations – your customer-facing portal is running ...

What’s New in Splunk Observability – September 2025

What's NewWe are excited to announce the latest enhancements to Splunk Observability, designed to help ITOps ...

Fun with Regular Expression - multiples of nine

Fun with Regular Expression - multiples of nineThis challenge was first posted on Slack #regex channel ...