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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...