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
Get Updates on the Splunk Community!

OpenTelemetry for Legacy Apps? Yes, You Can!

This article is a follow-up to my previous article posted on the OpenTelemetry Blog, "Your Critical Legacy App ...

UCC Framework: Discover Developer Toolkit for Building Technology Add-ons

The Next-Gen Toolkit for Splunk Technology Add-on Development The Universal Configuration Console (UCC) ...

.conf25 Community Recap

Hello Splunkers, And just like that, .conf25 is in the books! What an incredible few days — full of learning, ...