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:
copyraw
v_PaymentTerms = "Credit Note - 30 Days"; // we want the 30 from the above 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():
copyraw
v_PaymentTermsAlphaNum = v_PaymentTerms.getAlphaNumeric(); // yields CreditNote30Days vPaymentTermsNum = v_PaymentTermsAlphaNum.removeAllAlpha() // yields 30
- 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:
copyraw
v_PaymentTermsNumber = v_PaymentTerms.replaceAll("[^0-9]",""); // yields 30
- v_PaymentTermsNumber = v_PaymentTerms.replaceAll("[^0-9]","");
- // yields 30
And if working with money/currencies, a one liner to maintain the decimal point
copyraw
v_SalesAmount = "Total : £ 5.00"; v_SalesAmount = v_SalesAmount.replaceAll("[^0-9.]",""); // yields 5.00
- v_SalesAmount = "Total : £ 5.00";
- v_SalesAmount = v_SalesAmount.replaceAll("[^0-9.]","");
- // yields 5.00
Category: Zoho :: Article: 674