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!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

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