Splunk Search

How can we find out whether a string has three open parentheses characters?

danielbb
Motivator

We would like to find out whether a certain string has three open parentheses characters in any order. Can we do it with regex?

Tags (1)
0 Karma

Vijeta
Influencer

You can try like below example-

| makeresults |  eval str="(hgd(j,h(((sjs)ii))hhf))"
| rex field=str ".*\(.*\(.*\((?<test>.*).*"
|eval  flag=if(ISNOTNULL(test),"true","false")

darrenfuller
Contributor
| makeresults
| eval testdata="value with ( one open paren|value ( with ( two|value ( with ( three ( parens | value with three ((( together| (((value with three at the start|value with three at the end(((|((123)abcdefg(321)xxxx)|"
| rex field=testdata max_match=0 "(?<parenfields>[^\|]+)\|"
| fields + parenfields
| mvexpand parenfields
| regex parenfields="\(.*?\(.*?\("

darrenfuller
Contributor

I reread your question, you wanted to find out if a string has 3... this will do ...

| makeresults
| eval testdata="value with ( one open paren|value ( with ( two|value ( with ( three ( parens | value with three ((( together| (((value with three at the start|value with three at the end(((|((123)abcdefg(321)xxxx)|"
| rex field=testdata max_match=0 "(?<parenfields>[^\|]+)\|"
| fields + parenfields
| mvexpand parenfields
| eval HAS3parenS=if (match(parenfields, "\(.*?\(.*?\("), "Yes :D", "no :(")

gcusello
SplunkTrust
SplunkTrust

Hi danielbb,
surely!
if you share a sample I could help you.
Ciao.
Giuseppe

0 Karma

danielbb
Motivator

Thank you @gcusello - a string like this one is a valid one - ((123)abcdefg(321)xxxx)

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!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

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