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
SplunkTrust
SplunkTrust

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
SplunkTrust
SplunkTrust

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!

Improve Your Security Posture

Watch NowImprove Your Security PostureCustomers are at the center of everything we do at Splunk and security ...

Maximize the Value from Microsoft Defender with Splunk

 Watch NowJoin Splunk and Sens Consulting for this Security Edition Tech TalkWho should attend:  Security ...

This Week's Community Digest - Splunk Community Happenings [6.27.22]

Get the latest news and updates from the Splunk Community here! News From Splunk Answers ✍️ Splunk Answers is ...