Search code examples
zapier

Regex for Zapier to extract dollar amount


I'm using Zapier to pull dollar amounts out of emailed invoices to process them.

My first step in Zapier is a new email matching a search query, and I am able to get it to find the right email fine. To pull the $ amount out, I run a second step, Formatter by Zapier, and use transform -> extract pattern. For the regex pattern, I thought ^\$(([1-9]\d{0,2}(,\d{3})*)|(([1-9]\d*)?\d))(\.\d\d)?$ would work - but it's turning up false/no data.

Any one have any ideas that I should try? I'm admittedly not great at regex so I may have made a mistake above, so really appreciate any advice!

I would want to be able to pull any dollar amount format; but, the email will only have 1 per email, so it would just need to pull the first/only instance of the dollar amount in the email; it is in the body text of the email, and in format of either $X.XX, $XX.XX, $XXX.XX, or $X,XXX.XX (depends each instance).

Thank you!


Solution

  • Could you try using this

    [\$ ]+?(\d+([,\.\d]+)?)
    

    I ran some basic tests using the examples you gave and this should work. Alternatively, you may be able to get this out by using two Formatter - Split steps. One with a "$" delimiter, another with a " " blank space.

    The first Index should be the result you're looking for there.