Hey there,
We are trying to build an if statement that adjusts if the results of our extractregex produce an error, however it does not seem to be identifying the "error - not found" text.
This is how we have this built right now:
{if: Results1
=="[Error - No match found.]"}{=Results2}{else}{=Results1}{endif}
If this isn’t possible, my other thought is to test the results for the presence of digits, as our result we’re looking for is a number.
Thanks!
Hi @Peter_Monterubio ,
You could use testregex to test the string for a pattern.
If the result is "yes", get result 1, if "no" get result 2.
In the snippet below, I'm using testregex to check whether the contents of the paragraph field contain a phone number in the format xxx-xxxx.
{formparagraph: name=data; default=The phone number is 555-1234}
{if: testregex(data, "\d{3}-\d{4}")=="yes"}The text contains a valid phone number{else}The text does not contain a valid phone number{endif}
Would something like that work for you?
Perfect! Always over thinking my regex… lol
I was able to use this to test the result as being a digit.
{if: testregex(Results1, "\d")}{=Results1}{else}{=Results2}{endif}
Thanks so much!
1 Like
Cool
While we're on topic, have a look here:
Hi all,
Sometimes, you'll have a piece of text (copied into your clipboard or even extracted using {urlload}), and you want to extract a piece of information from it that matches a specific pattern, maybe a phone number in the pattern XXX-XXXX.
Text Blaze allows you to do this with the help of "Regular Expressions", a.k.a. regex.
There's a video with how to do this here:
[How to process and manipulate strings of text with regex in Text Blaze]
But in this thread, I would like you …
Would be cool to get some challenges from you
1 Like
Love the idea of that thread. Will definitely add some challenges!
The last hurdle we’re hitting with this one is using the result in a formtext. Our idea was to do something like this:
{if: testregex(Results1, "\d")}{formtext: default={=Results1}}{else}{formtext: default={=Results2}}{endif}
But it seems we can’t use declared values in a formtext field. I’m thinking we can go with something like this:
{if: testregex(Results1, "\d")}{=Results1}{elseif: testregex(Results2, "\d")}{=Results2}{else}{formtext: name=backup}{endif}
That way if neither show up a numerical result we can show the textbox for manual input.
@Peter_Monterubio - yes, that would be a good way of doing it.