Regex in handlebar to get everything after the first whitespace doesn't work during flow execution

For a name like "John B Doe", I need first name to be "John" and last name to be "B Doe".

While testing the handlebars statement in Dev playground the below statements work correctly.

{{regexMatch BuyerName "([^\s]+)"}} --> firstname
{{regexMatch BuyerName "(?<=\s).*"}}-->lastname

But when implemented in mapping and when flow is run, it throws invalid_handle_bar_expression

"Could not compile handle bar \"{{regexMatch BuyerName \"(?<=\\s).*\"}}\" because \"Invalid quantifier ?\" .Please correct and retry"

Why is it not able to compile when it worked in playground. Please help

Hi @ugenejude -

I created a Support ticket for this issue. You should receive an email with the information.

Thanks!

Kate

Thank you Kate

Hi Ugene -

I hope you're doing well.

Did you happen to come across a solution to this one?

- Merik

Here's where I landed:

{{#compare (regexSearch VendorName " ") ">" -1}}{{trim (substring VendorName (regexSearch VendorName " "))}}{{else}}.{{/compare}}

Explanation:

(regexSearch VendorName " ")
  • returns zero-indexed position of first space
  • returns -1 when string does not contain space
(substring VendorName (regexSearch VendorName " "))
  • returns substring starting with (inclusive) first space
  • it should be noted that I've already trimmed my VendorName on earlier export
  • there would be issues if VendorName had leading spaces
  • namely, this output intended to be Last Name would be equivalent to First Name
{{trim (substring VendorName (regexSearch VendorName " "))}}
  • removes whitespace present at start or end of substring
{{else}}.{{/compare}}
  • returns period in scenario where string does not contain a space

@merikducker Thank you for this workaround and explanation!! I ran into the same issue, and was able to get around it with your method. You just saved me a ton of time.

For anyone else wondering, the reason that this error occurs is because Javascript does not support lookahead / lookbehind, and "?" is involved in the process. You will need to find a different way to structure your formula that avoids lookaheads/lookbehinds.