Splunk Dev

Regex Help for Dashboard Field

zacksoft_wf
Contributor

I am changing the dashboard XML to perform an in-line field validation, but I cannot seem to get the regEx right.
Here is the sample XML code that I already have for another field. (In this example I am validating if the field entry is numeric or not).
My regex requirement is, It should be able to check if the input entered has any space in the beginning or end or if it has any doublequotes character in it. The regex should run inside the dashboard source code XML.

=======
<eval token="validationResult">if(match(value, "([^a-zA-Z0-9]\s?[^a-zA-Z0-9])\s$"), "trailing Punctuation or Space. [Remove any padded whitespaces or double quotes frov 'Value'] ", "No padded Punctuation or Space or doublequotes [No Action Required]"</eval>
========

Labels (1)
0 Karma
1 Solution

johnhuang
Motivator

There's no need to conditional match if your goal is to sanitize the input.

<input type="text" token="value">
<label>Value</label>
<change>
<eval token="value">trim(replace(value, "\"", "")</eval>
</change>
</input>

View solution in original post

johnhuang
Motivator

Assuming "value" is the original token name and "validationResult" becomes the new token, the code below will remove leading and trailing spaces, and remove double quotes.

<eval token="validationResult">trim(replace($value$, "\"", "")</eval>

zacksoft_wf
Contributor

@johnhuang  -Thanks. 
The way I wanted to implement isn't yielding me result. It is failing.
I was thinking, is there any way I could condition match and put the same regex logic.
So I tried it but it didn't help..Could you suggest any simpler implementation , to validate this text field.

<input type="text" token="value">
<label>Value</label>
<condition match ..>
</condition>

 

 

 

 

0 Karma

johnhuang
Motivator

There's no need to conditional match if your goal is to sanitize the input.

<input type="text" token="value">
<label>Value</label>
<change>
<eval token="value">trim(replace(value, "\"", "")</eval>
</change>
</input>

zacksoft_wf
Contributor

@johnhuang  - Such a simple yet brilliant solution. I got what I wanted.  Thank you so much, Sir.  

Get Updates on the Splunk Community!

New Year, New Changes for Splunk Certifications

As we embrace a new year, we’re making a small but important update to the Splunk Certification ...

[Puzzles] Solve, Learn, Repeat: Unmerging HTML Tables

[Puzzles] Solve, Learn, Repeat: Unmerging HTML TablesFor a previous puzzle, I needed some sample data, and ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...