Using If Commands to try to reduce "No Match Found" prompts

Hello Community!

I am using the website tool to extract phone numbers from a website to send texts. I have a couple of things I am trying to figure out to make the snippets a little easier to read.

First, some profiles have multiple numbers so I am using the multiple option in the website feature. However, when the numbers are pulled, they are in this format, ["555-555-555", "555-555-5555"] which our phone application does not read. To fix this I am using this formula:

{phonenumber1=split({site: text; select=ifneeded; selector=#phone_number\ ; multiple=yes}, ",")[1]}{=extractregex(phonenumber1, "\w+-\w+-\w+")}

My problem is that 80% of the time, the phone number is formulated as 555-555-5555, but there are instances that it is formulated without the dashes. Is there another regex combination that will extract the numbers regardless of what format they are in?

Second issue: When running the snippet, some of the boxes will be empty and it will return a prompt like you see below:


This just means that those boxes were left empty which is not an issue. The only ones I really want to focus on are when they are both empty like this:


Is there a way for me to tell the snippet:

  • IF "Name1" is not found but "phonenumber1" is found", then return the text "Name Missing" instead of the "No Match Found" prompt.

  • IF "Name1" is found but "phonenumber1" is not found" then return the text "Phone number missing" instead of the "No Match Found" prompt.

  • IF "Name1" is not found AND "phonenumber1" is not found", then do nothing

It would look something like this:

Pic 4

Here is the snippet:

{note}{Name1=split({site: text; select=ifneeded; selector=[name="phone_description"]\ ; multiple=yes}, ",")[1]}{=extractregex(name1, "\w+")}: {endnote}{phonenumber1=split({site: text; select=ifneeded; selector=#phone_number\ ; multiple=yes}, ",")[1]}{=extractregex(phonenumber1, "\w+-\w+-\w+")}

Thank you!


Hey @Jennifer_Saavedra,
What a cool snippet.

I think that the answer to both of your questions is either the catch command, which evaluates a statement and if it returns an error, evaluates another statement or the testregex command which returns true if a pattern is found.

So your first snippet could be:

{phonenumber1=split({site: text; select=ifneeded; selector=#phone_number\ ; multiple=yes}, ",")[1]}{=catch(extractregex(phonenumber1, "\w+-\w+-\w+"), extractregex(phonenumber1, "\w+"))}

Or it could be:

{phonenumber1=split({site: text; select=ifneeded; selector=#phone_number\ ; multiple=yes}, ",")[1]}{if: testregex(phonenumber1, "\w+-\w+-\w+")}{=extractregex(phonenumber1, "\w+-\w+-\w+")}{else}{=extractregex(phonenumber1, "\w+")}{endif}

1 Like

@Dan_Barak1 It works perfectly! I thought the answer might be the catch command but I couldn't quite figure out how to set it up and it kept giving me an error. Thank you!

Quick note that {site: text;...multiple=yes} already returns an array. So we can use [1] to directly access its first element. We don't need to split on the , and then take the first element.

Here's a simplified version:

{phonenumber1={site: text; select=ifneeded; selector=#phone_number\ ; multiple=yes}[1]}{if: testregex(phonenumber1, "\w+-\w+-\w+")}{=extractregex(phonenumber1, "\w+-\w+-\w+")}{else}{=extractregex(phonenumber1, "\w+")}{endif}

Thank you Gaurang! That makes my snippet easier to read.