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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...