Splunk Search

Help building regex for searches based on cs_username field.

Vfinney
Observer

I'm having no luck building a regex to match cs_usernames. What I'm looking for are two separate searches both based on the
cs_username field. The first search is to find all instances where the usernames are in all CAPS. The second search is to find usernames that end in at least two digits. Example of logs are below:

2020-05-15 04:58:34 10.140.14.228 POST /NotAvailable.aspx - 80 Gerardot 10.140.15.235 Mozilla/5.0+(Linux;+Android+9;+SM-G960U)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/74.0.3729.136+Mobile+Safari/537.36  302 0 0 15 172.69.69.111

2020-05-15 04:57:19 10.140.14.228 POST /Account/Login.aspx - 80 Kaitlyn1230 10.140.15.235 Mozilla/5.0+(iPhone;+CPU+iPhone+OS+13_4+like+Mac+OS+X)+AppleWebKit/605.1.15+(KHTML,+like+Gecko)+GSA/107.0.310639584+Mobile/15E148+Safari/604.1 200 0 0 46 162.158.75.109

2020-05-15 04:54:24 10.140.14.228 POST /PaymentInfo.aspx - 80 Emulbah 10.140.15.235 Mozilla/5.0+(Windows+NT+6.1;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/81.0.4044.138+Safari/537.36  302 0 0 46 172.68.150.39
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @Vfinney,
try the following regex

^\d+-\d+-\d+\s+\d+:\d+:\d+\s+\d+\.\d+\.\d+\.\d+\s+\w+\s\/[^ ]+\s+[^ ]+\s+\d+\s+(?<cs_username>[^ ]+)\s+

or using the rex command

your_search
| rex "^\d+-\d+-\d+\s+\d+:\d+:\d+\s+\d+\.\d+\.\d+\.\d+\s+\w+\s\/[^ ]+\s+[^ ]+\s+\d+\s+(?<cs_username>[^ ]+)\s+"
| ...

that you can test at https://regex101.com/r/xyPcQj/1

Ciao.
Giuseppe

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Vfinney,
try the following regex

^\d+-\d+-\d+\s+\d+:\d+:\d+\s+\d+\.\d+\.\d+\.\d+\s+\w+\s\/[^ ]+\s+[^ ]+\s+\d+\s+(?<cs_username>[^ ]+)\s+

or using the rex command

your_search
| rex "^\d+-\d+-\d+\s+\d+:\d+:\d+\s+\d+\.\d+\.\d+\.\d+\s+\w+\s\/[^ ]+\s+[^ ]+\s+\d+\s+(?<cs_username>[^ ]+)\s+"
| ...

that you can test at https://regex101.com/r/xyPcQj/1

Ciao.
Giuseppe

0 Karma

to4kawa
Ultra Champion

your log is space delimited.

why do not you use \s and \S?

or try Field Extracter

0 Karma
Get Updates on the Splunk Community!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

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

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...