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!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...