Two different RegEx replacements in one handlebar?

Comments

5 comments

  • Courtney Jordan Experience Strategy & Design Director Community moderator
    Celigo University Level 4: Legendary
    Awesome Follow-up
    Top Contributor

    Hi Jake Naydock!
    Thank you so much for sharing your solution and for letting us know that a previous community post helped you!

    1
  • Jake Naydock
    Great Answer

    I found a workaround to this problem - I was able to use regex to grab the first half of the SKU before the space, regex to grab the second half between the space and "-FBA", and join them together with "-" to get the value I wanted. Here is the handlebar:

    {{join "-" (regexMatch SellerSKU "\S*") (regexMatch SellerSKU "(?<=\s)[^-]*")}}

     

    With this handlebar, SKU 12223 4556-FBA would properly output to 12223-4556

    0
  • Jake Naydock
    Great Answer

    Note that the above also did not work in the flow (resulted in invalid quantifier "?"), but it worked in the dev playground .

    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.

    Here is how I reconstructed this formula, and this now works in the flow:

    {{join "-" (regexMatch OrderItem[*].SellerSKU "\S*") (trim (substring OrderItem[*].SellerSKU (regexSearch OrderItem[*].SellerSKU " ") (regexSearch OrderItem[*].SellerSKU "-FBA")))}}

    This other community post/link helped me a lot here, I recommend checking this out if you run into the same issue: https://docs.celigo.com/hc/en-us/community/posts/360078177872-Regex-in-handlebar-to-get-everything-after-the-first-whitespace-doesn-t-work-during-flow-execution

     

     

    0
  • Jake Naydock
    Great Answer

    Hi Courtney Jordan,

    No problem! Do you know why certain things will work in the Dev playground, but not in the flow itself? I was surprised to see that my regex worked when testing, but ended up having to rethink the whole process after trying to put it in place. Sometimes I will notice inconsistencies between Dev playground behavior and flow behavior, and wanted to see if you or anyone has insight as to what causes that.

    Thanks,

    Jake

    0
  • Courtney Jordan Experience Strategy & Design Director Community moderator
    Celigo University Level 4: Legendary
    Awesome Follow-up
    Top Contributor

    Hi Jake Naydock,

    Thanks for letting us know about this discrepancy. I am following up with the PM in charge of flow builder.

    0

Please sign in to leave a comment.