Splunk Search

Field Extraction regex, stop at word or $

JDukeSplunk
Builder

So I have some data that I'm trying to extract the application name from. These are Citrix ICA syslog events.

Here's the 2 snippets I'm trying to match. One I'd like to stop at " - startTime" the other stop at the $. Both are the same field applicationName.

applicationName SXe Staging GCAST-2 - startTime
applicationName HDS 2016 VIRTUAL DESKTOP TEST $S88-166 - startTime

The italic text is what I'd like to get for the field value "applicationName"

Here is what I have come up with that does capture to - startTime.

 rex "applicationName (?<AAAAAAA>.+)(?=(\s-\sstartTime))"

However when I try

     rex "applicationName (?<AAAAAAA>.+)(?=(\s-\sstartTime|$))" 
     rex "applicationName (?<AAAAAAA>.+)(?=(\s-\sstartTime|\$))" 
     rex "applicationName (?<AAAAAAA>.+)(?=(\s-\sstartTime|\\$))" 
     rex "applicationName (?<AAAAAAA>[^$].+)(?=(\s-\sstartTime))" 
     rex "applicationName (?<AAAAAAA>[^\$|startTime].+)"

It doesn't quite work right. Anyway I'm just trying to limit the results to actual application names, not this extra bit of data that Citrix someone has thrown into the field.

Like these, the two Windows 10 events should really be the same field value.
SXe Staging GCAST-2
HDS 2016 VIRTUAL DESKTOP TEST $S88-166
Canada Greatplains
Windows 10 $A41-29-3D5DDA4A-0001
aSa ex Menu
Windows 10 $A67-37-3D5C3C71-0001

0 Karma
1 Solution

manjunathmeti
Champion

hi @JDukeSplunk,

Try this regex:

| rex "applicationName\s(?<application_name>[^\$]+).*\s-\sstartTime"

Sample query:

| makeresults 
| eval _raw="_raw
applicationName SXe Staging GCAST-2 - startTime
applicationName HDS 2016 VIRTUAL DESKTOP TEST $S88-166 - startTime
applicationName Canada Greatplains - startTime
applicationName Windows 10 $A41-29-3D5DDA4A-0001 - startTime" 
| multikv forceheader=1 
| rex "applicationName\s(?<application_name>[^\$]+).*\s-\sstartTime"

View solution in original post

0 Karma

woodcock
Esteemed Legend

Like this:

\s+(?<capture>.*?)\s+(?:-|\$)

See here:
https://regex101.com/r/TZlhtj/1

0 Karma

JDukeSplunk
Builder

In fairness, both regex's here work equally well. I just wanted to give @manjunathmeti the credit because his points are lower.

Thanks both of you.

woodcock
Esteemed Legend

As you should. I also think his is probably better, too.

0 Karma

manjunathmeti
Champion

hi @JDukeSplunk,

Try this regex:

| rex "applicationName\s(?<application_name>[^\$]+).*\s-\sstartTime"

Sample query:

| makeresults 
| eval _raw="_raw
applicationName SXe Staging GCAST-2 - startTime
applicationName HDS 2016 VIRTUAL DESKTOP TEST $S88-166 - startTime
applicationName Canada Greatplains - startTime
applicationName Windows 10 $A41-29-3D5DDA4A-0001 - startTime" 
| multikv forceheader=1 
| rex "applicationName\s(?<application_name>[^\$]+).*\s-\sstartTime"
0 Karma
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 ...