Splunk Search

How do I extract a field between two strings using a regular expression?

rohanmiskin
Explorer

I have logs having string like:

127.0.0.1|> GET /alldata
127.0.0.1|> GET /somedata
127.0.0.1|> GET /nodata
127.0.0.1|> POST /nodata
127.0.0.1|> PUT /nodata
127.0.0.1|> DELETE /nodata

I want to extract the field between 127.0.0.1|> and /
i.e i need GET,POST,PUT,DELETE to be in an extracted field.

NOTE: There's a space after > and before /

0 Karma

vnravikumar
Champion

Hi @rohanmiskin

Try this and let me know

| makeresults 
| eval sampledata ="127.0.0.1|> GET /somedata" 
| rex field="sampledata" ">\s(?P<method>.*)\s\/"
0 Karma

renjith_nair
Legend

@rohanmiskin ,

Try

"\>\s(?<ACTION>\w+)"
Happy Splunking!
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...