Regex help for SAINT Rule Builder | Community
Skip to main content
New Participant
Jul 7, 2020 8:58 PM UTC
Solved

Regex help for SAINT Rule Builder

Currently have strings coming in with two formats. Some strings end with the character “|” and other strings do not. For example, one value might is “ush|park-map|” and another value is “ush|theme-parks”. The goal is to remove the last pipe “|” from the string IF the string ends with a “|”.

In the SAINT Rule Builder, I was able to remove the last pipe “|” from strings that ended with a pipe “|”. However in the final output, the strings that did NOT end in a pipe had “**Unmatched**” as the final value (1st screenshot below).  The question is how can you return the original/default value if the string doesn’t meet the rule criteria (aka ending with a “|”)?  

 

We'd greatly appreciate your help, thanks!

 

David

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Alexis_Cazes_
Alexis_Cazes_Accepted solution
Level 10
Jul 14, 2020 3:21 PM UTC

The correct regex is (.+)(\|)?$

 

Notice the ? at the end of (\|) which stand of zero or one of pipe

6 replies

jantzen_b
Employee
Feb 3, 2021 9:35 PM UTC
Do any of the answers below answer your initial question? If so, can you select one of them as the correct answer? If none of the answers already provided answer your question, can you provide additional information to better help the community solve your question?
Translate
PratheepArunRaj
New Participant
Jul 15, 2020 8:14 AM UTC

Dear Dabressler,

You just need to stack the conditions properly. Below you go:

And the test results are as below:

I Hope, this is what you are expecting.

Thank You, Arun.

Translate
Alexis_Cazes_
Alexis_Cazes_Accepted solution
Level 10
Jul 14, 2020 3:21 PM UTC

The correct regex is (.+)(\|)?$

 

Notice the ? at the end of (\|) which stand of zero or one of pipe

Translate
Alexis_Cazes_
Level 10
Jul 14, 2020 3:20 PM UTC
SO basically you are saying there is either zero or one of pipe at the end like a? Zero or one of a
Translate
Alexis_Cazes_
Level 10
Jul 14, 2020 3:19 PM UTC
try this (.+)(\|)?$
Translate
Level 4
Jul 8, 2020 2:34 AM UTC

I'm not very knowledgeable about regex, but I think you can adapt this to work for your use case.

^((.+)\_(.+)\_(.+)\_(.+)\_(.+)\_(.+)|(.+)\_(.+)\_(.+)\_(.+)\_(.+))$

In this case $2$8 mapped to the first field (depending on if there are 4 or 5 underscores.  You could shift and shorten this for the pipe.

Translate