Splunk Search

Regex search help

nangrosso
Engager

I was asked to " update a search to append a final ' | regex PatternStringMatch="[A-Z]" query that will look for anything in that field that has both a letter and a number. Any thoughts?

Labels (1)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

The OP ask is "has both a letter and a number" (underline is mine).  "\w" will match any single character that is not a "punctuation", so "a" (no number), "1" (no letter), "___" (no letter or number), "a_b_c_", "1_2_3_", etc., will all match.  The following will match "both a letter and a number":

| regex PatternStringMatch="[a-zA-Z].*\d|\d.*[a-zA-Z]"

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| regex PatternStringMatch="\w"
0 Karma

nangrosso
Engager

Thanks for the response but I ran the search it gave me nothing. Any idea what the "W" represents 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

backslash lower case w means numbers and letters. upper case letters means not numbers and letters. So, the regex will keep events where the field has letters or numbers. Is this not what you wanted?

0 Karma

yuanliu
SplunkTrust
SplunkTrust

The OP ask is "has both a letter and a number" (underline is mine).  "\w" will match any single character that is not a "punctuation", so "a" (no number), "1" (no letter), "___" (no letter or number), "a_b_c_", "1_2_3_", etc., will all match.  The following will match "both a letter and a number":

| regex PatternStringMatch="[a-zA-Z].*\d|\d.*[a-zA-Z]"

0 Karma

nangrosso
Engager

Thanks for the detailed explanation 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You are right, the specification is ambiguous - \w with match both a letter and a number (and non-punctuation).

0 Karma
Get Updates on the Splunk Community!

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 at Splunk .conf24 ...

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

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

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