A quick post on how I managed to build a regex to extract all non-numeric characters (all non-digits) from a string.
Why?
I only want the digits/numbers from a string:
v_PaymentTerms = "Credit Note - 30 Days";
// we want the 30 from the above string
How?
I'm aware of the getAlphaNumeric() function in Zoho and I can remove the letters with removeAllAlpha():
v_PaymentTermsAlphaNum = v_PaymentTerms.getAlphaNumeric();
// yields CreditNote30Days
vPaymentTermsNum = v_PaymentTermsAlphaNum.removeAllAlpha()
// yields 30
But just to demo a regex and a one liner, here's a typical regular expression (match all characters not from 0 to 9) in a Zoho Deluge script:
v_PaymentTermsNumber = v_PaymentTerms.replaceAll("[^0-9]","");
// yields 30
And if working with money/currencies, a one liner to maintain the decimal point
v_SalesAmount = "Total : £ 5.00";
v_SalesAmount = v_SalesAmount.replaceAll("[^0-9.]","");
// yields 5.00
Discussion
Comments
Questions, corrections and useful additions are reviewed before appearing here.
No comments yet. Start the discussion.