Splunk Search

How to pass regular expression in variable to the match?

rsathish47
Contributor

HI All,

     How to pass regular expression to the variable to match command? Please help..

in Following search query we need to pass the value for nonsupporting days dynamically based on the criteria.

| gentimes start=-1 | eval CreateDateEpoch="1412136000" | table CreateDateEpoch | eval start=relative_time(CreateDateEpoch,"@d") | eval end=relative_time(now(),"@d") | eval Date=mvrange(start,end+86400,86400) | convert ctime(Date) timeformat="%+" | eval NoOfBusinessDays=mvcount(mvfilter(NOT match(Date,"(Sun|Sat).*")))

Ex:
eval nonsupport=if(value=1,"(Sun|Sat).*","(Mon|Sun).") | eval NoOfBusinessDays=mvcount(mvfilter(NOT match(Date,nonsupport*))

Thanks
Sathish Rangan

Tags (3)
0 Karma

woodcock
Esteemed Legend

You can either do this with a macro or with map. For an example of the latter, check out this answer:

https://answers.splunk.com/answers/386488/regex-in-lookuptable.html

0 Karma

richgalloway
SplunkTrust
SplunkTrust

A untested idea: put the variable name within single-quotes. ... | match(Date, 'nonsupport') ...

---
If this reply helps you, Karma would be appreciated.
0 Karma

rsathish47
Contributor

not working ;(

0 Karma
Get Updates on the Splunk Community!

Aligning Observability Costs with Business Value: Practical Strategies

 Join us for an engaging Tech Talk on Aligning Observability Costs with Business Value: Practical ...

Mastering Data Pipelines: Unlocking Value with Splunk

 In today's AI-driven world, organizations must balance the challenges of managing the explosion of data with ...

Splunk Up Your Game: Why It's Time to Embrace Python 3.9+ and OpenSSL 3.0

Did you know that for Splunk Enterprise 9.4, Python 3.9 is the default interpreter? This shift is not just a ...