Regex Match only returns first match - VisualCron - Forum

Community forum

  •  dhl
  • Paid support Topic Starter
I'm parsing the subject of an email-trigger and storing some selected values in variables, but I get som issues with the Regex(Match|...) function, in that it only returns the first match.

I've made a small test to easily replicate the 'wrong' behavior of REGEX(Match...)
{REGEX(Match|Status 35412 Mike Allan John 3-12-2018|([^Status][aA-zZ]+))}
Returns: Mike
Should return: Mike Allan John

If I try the same regex in 
Regular expression: [^Status][aA-zZ]+
Test string: Status 35412 Mike Allan John 3-12-2018
I get Mike Allan John as i expected...

So it seems that the expression is correct but REGEX(Match|...) isn't working (at least not as I expect it to) ?
Can you describe what text you want to return? In other words, "match not 'Status' at the start of the string, and if found return the alphabetic characters after the word 'Status'".
Are there always a set of numbers between the word status and the text you want? Are there always numbers (date?) after? What if any of these components are missing? Always expect the unexpected!

Without knowing your rules, here's a first stab at it.

Match a string that starts with the word 'Status' (anchored to the front of the string), followed by a space and one or more numbers and another space. Capture everything encountered until a space and the rest of the string (anchored to the end of the line). Returned the first captured group (surrounded by parenthesis). Note if a match is not found NULL is returned.

{REGEX(MatchGetGroup|Status 35412 Mike Allan John 3-12-2018|^Status \d+ (.*) .*$|1)}
  •  dhl
  • Paid support Topic Starter
Hi Gary,

Thank you so much for taking a stab at it - and sorry I've been away a few days!

You are my hero 🙂 Your solution works like a charm.

If I try to just exchange the Match with MatchGetGroup in my old version, I suddenly get an error with "Error in argument" using the same regex that works using just Match - but as soon as I also change the regex to your version, everything works like a charm and I get my name with alle three words in it - thanks!!

I will look into MatchGetGroup as I clearly dont understand that part yet :-)

Glad I could help. Take a close look at the arguments to Match vs MatchGetGroup. Match returns what is matched by the regex in the last argument, where MatchGetGroup lets you describe a larger, more complex regex and surround the part you want to return (the group) with parenthesis. Consider Replace as well as it allows different functionality to keep in mind. It replaces the string with what is returned from your match regex. Here for example, each set of one or more non-digit character sets (followed by a space that is not captured) are captured in groups, and returned in reverse order with a dash separating them. In Replace, the captured groups are referenced numerically as they are encountered from left to right and are preceded by a dollar sign.

{REGEX(Replace|Status 35412 Mike Allan John 3-12-2018|^Status \d+ (\D+) (\D+) (\D+) .*$|$3-$2-$1)}

Scroll to Top