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!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...