For Zoho Services only:


I'm actually part of something bigger at Ascent Business Solutions recognized as the top Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions offer support for smaller technical fixes and projects for larger developments, such as migrating to a ZohoCRM.  A team rather than a one-man-band is always available to ensure seamless progress and address any concerns. You'll find our competitive support rates with flexible, no-expiration bundles at http://ascentbusiness.co.uk/zoho-support-2.  For larger projects, check our bespoke pricing structure and receive dedicated support from our hands-on project consultants and developers at http://ascentbusiness.co.uk/crm-solutions/zoho-crm-packages-prices.

The team I manage specializes in coding API integrations between Zoho and third-party finance/commerce suites such as Xero, Shopify, WooCommerce, and eBay; to name but a few.  Our passion lies in creating innovative solutions where others have fallen short as well as working with new businesses, new sectors, and new ideas.  Our success is measured by the growth and ROI we deliver for clients, such as transforming a garden shed hobby into a 250k monthly turnover operation or generating a +60% return in just three days after launch through online payments and a streamlined e-commerce solution, replacing a paper-based system.

If you're looking for a partner who can help you drive growth and success, we'd love to work with you.  You can reach out to us on 0121 392 8140 (UK) or info@ascentbusiness.co.uk.  You can also visit our website at http://ascentbusiness.co.uk.

Zoho Deluge - Some Useful Regular Expressions

What
A more comprehensive post on some other regex (regular expressions) to format values in Zoho.

How?
The following will remove any non-digits:
copyraw
v_MyString = "<b>Hello World 123</b>";
v_MyFormattedString = v_MyString.replaceAll("[^0-9]","");
// yields 123
  1.  v_MyString = "<b>Hello World 123</b>"
  2.  v_MyFormattedString = v_MyString.replaceAll("[^0-9]","")
  3.  // yields 123 

The following is used in searches to escape special characters with a backslash:
copyraw
v_MyString = "Joe's \"Amazing\" Skill &  Sidekick (1)";
v_FormattedString = v_MyString.replaceAll(("([&'\"\%()])"),"\\$1",true);
// yields Joe\'s \"Amazing\" Skill \& \ Sidekick \(1\)

v_FormattedString = v_MyString.replaceAll("%"),"\u0025",true);
  1.  v_MyString = "Joe's \"Amazing\" Skill &  Sidekick (1)"
  2.  v_FormattedString = v_MyString.replaceAll(("([&'\"\%()])"),"\\$1",true)
  3.  // yields Joe\'s \"Amazing\" Skill \& \ Sidekick \(1\) 
  4.   
  5.  v_FormattedString = v_MyString.replaceAll("%"),"\u0025",true)

The following will strip all HTML/XML tags:
copyraw
v_MyString = "<b style='color:red'>Hello World 123</b>";
v_MyFormattedString = v_MyString.replaceAll("<(.|\n)*?>","");
// yields Hello World 123
  1.  v_MyString = "<b style='color:red'>Hello World 123</b>"
  2.  v_MyFormattedString = v_MyString.replaceAll("<(.|\n)*?>","")
  3.  // yields Hello World 123 

URL safe slug:
copyraw
v_MyString = "Hello World 123";
v_MyFormattedString = v_MyString.toLowerCase().replaceAll(" ","-");
v_MyFormattedString = v_MyFormattedString.replaceAll("[^a-z0-9-]+","");
// yields hello-world-123
  1.  v_MyString = "Hello World 123"
  2.  v_MyFormattedString = v_MyString.toLowerCase().replaceAll(" ","-")
  3.  v_MyFormattedString = v_MyFormattedString.replaceAll("[^a-z0-9-]+","")
  4.  // yields hello-world-123 

Email safe string:
copyraw
v_MyString = "somewhere[]@beyondthesea_1.com";
v_MyFormattedString = v_MyString.toLowerCase().trim();
v_MyFormattedString = v_MyFormattedString.replaceAll("[^a-z0-9@\-.]+","");
// yields This email address is being protected from spambots. You need JavaScript enabled to view it.
  1.  v_MyString = "somewhere[]@beyondthesea_1.com"
  2.  v_MyFormattedString = v_MyString.toLowerCase().trim()
  3.  v_MyFormattedString = v_MyFormattedString.replaceAll("[^a-z0-9@\-.]+","")
  4.  // yields This email address is being protected from spambots. You need JavaScript enabled to view it. 

Replace any duplicates:
copyraw
v_MyString = "Hello World Hello Joe";
v_MyFormattedString = v_MyString.replaceAll("(\b\w+\b)(?=.*\b\1\b)","");
// yields World Hello Joe
  1.  v_MyString = "Hello World Hello Joe"
  2.  v_MyFormattedString = v_MyString.replaceAll("(\b\w+\b)(?=.*\b\1\b)","")
  3.  // yields World Hello Joe 

Remove block comments:
copyraw
v_MyRegEx = "(\/\*([^*]|(\*+[^*\/]))*\*+\/)";
v_MyString = "String to output: /* this is a comment */";
v_MyFormattedString = v_MyString.replaceAll(v_MyRegEx,"");
// yields String to output:
  1.  v_MyRegEx = "(\/\*([^*]|(\*+[^*\/]))*\*+\/)"
  2.  v_MyString = "String to output: /* this is a comment */"
  3.  v_MyFormattedString = v_MyString.replaceAll(v_MyRegEx,"")
  4.  // yields string to output: 

Zoho Deluge Validation Checking by Regular Expression:

So I could do it the long way in Zoho Deluge. We match a pattern and replace everything out that conforms to the criteria so a true response will be an empty string:
copyraw
v_MyRegEx = "^[A-Za-z0-9._-]+@[A-Za-z0-9._-]+\.[A-Za-z]{2,}$";
v_MyString = "This email address is being protected from spambots. You need JavaScript enabled to view it.";
v_MyFormattedString = v_MyString.replaceAll(v_MyRegEx,"");
b_Ok = if( v_MyFormattedString == "", true, false);
// yields true

v_MyString = "somewhere[]@beyondthesea_1.com";
v_MyFormattedString = v_MyString.replaceAll(v_MyRegEx,"");
b_Ok = if( v_MyFormattedString == "", true, false);
// yields false
  1.  v_MyRegEx = "^[A-Za-z0-9._-]+@[A-Za-z0-9._-]+\.[A-Za-z]{2,}$"
  2.  v_MyString = "This email address is being protected from spambots. You need JavaScript enabled to view it."
  3.  v_MyFormattedString = v_MyString.replaceAll(v_MyRegEx,"")
  4.  b_Ok = if( v_MyFormattedString == "", true, false)
  5.  // yields true 
  6.   
  7.  v_MyString = "somewhere[]@beyondthesea_1.com"
  8.  v_MyFormattedString = v_MyString.replaceAll(v_MyRegEx,"")
  9.  b_Ok = if( v_MyFormattedString == "", true, false)
  10.  // yields false 

Yay Zoho has "matches". So this is the regex way to do it:
copyraw
v_MyRegEx = "^[A-Za-z0-9._-]+@[A-Za-z0-9._-]+\.[A-Za-z]{2,}$";
v_MyString = "This email address is being protected from spambots. You need JavaScript enabled to view it.";
b_Ok = if( v_MyString.matches( v_MyRegEx  ), true, false);
// yields true
  1.  v_MyRegEx = "^[A-Za-z0-9._-]+@[A-Za-z0-9._-]+\.[A-Za-z]{2,}$"
  2.  v_MyString = "This email address is being protected from spambots. You need JavaScript enabled to view it."
  3.  b_Ok = if( v_MyString.matches( v_MyRegEx  ), true, false)
  4.  // yields true 

Some other validation checks:
copyraw
// validate UK postcode
v_MyRegEx = "^((([A-PR-UWYZ])([0-9][0-9A-HJKS-UW]?))|(([A-PR-UWYZ][A-HK-Y])([0-9][0-9ABEHMNPRV-Y]?))\s{0,2}(([0-9])([ABD-HJLNP-UW-Z])([ABD-HJLNP-UW-Z])))|(((GI)(R))\s{0,2}((0)(A)(A)))$";
  1.  // validate UK postcode 
  2.  v_MyRegEx = "^((([A-PR-UWYZ])([0-9][0-9A-HJKS-UW]?))|(([A-PR-UWYZ][A-HK-Y])([0-9][0-9ABEHMNPRV-Y]?))\s{0,2}(([0-9])([ABD-HJLNP-UW-Z])([ABD-HJLNP-UW-Z])))|(((GI)(R))\s{0,2}((0)(A)(A)))$"

Some XML bits:
copyraw
v_MyRegEx = "<!\[CDATA\[([^\]]*)\]\]>";
v_MyString = "<tag1><![CDATA[my_real_textual_data]]></tag1>";
v_FormattedString = v_MyString.replaceAll(v_MyRegEx,"$1",false);
// yields <tag1>my_real_textual_data</tag1>
  1.  v_MyRegEx = "<!\[CDATA\[([^\]]*)\]\]>"
  2.  v_MyString = "<tag1><![CDATA[my_real_textual_data]]></tag1>"
  3.  v_FormattedString = v_MyString.replaceAll(v_MyRegEx,"$1",false)
  4.  // yields <tag1>my_real_textual_data</tag1> 


Additional
Since writing this article I found a Zoho page with some other pretty useful regular expressions at https://zoholic.blogspot.com/2015/04/some-usefull-regex-in-zoho.html:

Convert a string of characters to a list:
copyraw
v_MyString = "12345";
l_StringValues = v_MyString.replaceAll("(?)",",",false).removeFirstOccurence(",").removeLastOccurence(",").toList();
// yields list of [1,2,3,4,5]

// NB: "1mySep2mySep3mySep4mySep5".toList("mySep");
// yields list of [1,2,3,4,5]
  1.  v_MyString = "12345"
  2.  l_StringValues = v_MyString.replaceAll("(?)",",",false).removeFirstOccurence(",").removeLastOccurence(",").toList()
  3.  // yields list of [1,2,3,4,5] 
  4.   
  5.  // NB: "1mySep2mySep3mySep4mySep5".toList("mySep")
  6.  // yields list of [1,2,3,4,5] 

Replace any multiple spaces with a single space:
copyraw
v_MyString = "Hello   World!";
v_FormattedString = v_MyString.replaceAll("[ ]+"," ",false); 
// yields Hello World!
  1.  v_MyString = "Hello   World!"
  2.  v_FormattedString = v_MyString.replaceAll("[ ]+"," ",false)
  3.  // yields Hello World! 

Remove consecutive duplicate words:
copyraw
// replace consecutive duplicates
v_MyString = "Hello Hello Joe";
v_FormattedString = v_MyString.replaceAll(("([A-Za-z]+) \1"),"$1",false);
// yields Hello Joe

// NB: v_MyString = "Hello World Hello Joe"
// yields Hello World Hello Joe
  1.  // replace consecutive duplicates 
  2.  v_MyString = "Hello Hello Joe"
  3.  v_FormattedString = v_MyString.replaceAll(("([A-Za-z]+) \1"),"$1",false)
  4.  // yields Hello Joe 
  5.   
  6.  // NB: v_MyString = "Hello World Hello Joe" 
  7.  // yields Hello World Hello Joe 

Escape/Backslash some special characters:
copyraw
v_MyString = "Joe's \"Amazing\" Skill & <His> Grunt";
v_FormattedString = v_MyString.replaceAll(("([&'\"<>])"),"\\$1",false);
// yields Joe\'s \"Amazing\" Skill \& \<His\> Grunt
  1.  v_MyString = "Joe's \"Amazing\" Skill & <His> Grunt"
  2.  v_FormattedString = v_MyString.replaceAll(("([&'\"<>])"),"\\$1",false)
  3.  // yields Joe\'s \"Amazing\" Skill \& \<His\> Grunt 

Replace new lines in returned JSON (invalid in Zoho):
copyraw
v_MyString = "{"MyKey":"MyValue
"}";

// the long way (and cos the regex for this isn't working)
v_FormattedString = v_MyString.replaceAll("\r","",false);  // carriage returns
v_FormattedString = v_MyString.replaceAll("\n","",false);  // line feeds
v_FormattedString = v_MyString.replaceAll("\f","",false);  // form feeds

// a regex that should work but doesn't
v_FormattedString = v_MyString.replaceAll(("([\n\r])"),"",false);
  1.  v_MyString = "{"MyKey":"MyValue 
  2.  "}"
  3.   
  4.  // the long way (and cos the regex for this isn't working) 
  5.  v_FormattedString = v_MyString.replaceAll("\r","",false);  // carriage returns 
  6.  v_FormattedString = v_MyString.replaceAll("\n","",false);  // line feeds 
  7.  v_FormattedString = v_MyString.replaceAll("\f","",false);  // form feeds 
  8.   
  9.  // a regex that should work but doesn't 
  10.  v_FormattedString = v_MyString.replaceAll(("([\n\r])"),"",false)

Split a string by a word:
copyraw
v_MyString = "PoshDavid Beckham";
v_FormattedString = v_MyString.replaceAll("\b(Posh)([^ ]*)","$1 and $2",false);
// yields Posh and David Beckham
  1.  v_MyString = "PoshDavid Beckham"
  2.  v_FormattedString = v_MyString.replaceAll("\b(Posh)([]*)","$1 and $2",false)
  3.  // yields Posh and David Beckham 

UK/US Decimal Separator and Commas:
copyraw
v_MyString = 1234.567;
v_FormattedString = (v_MyString.round(2)).toString().replaceAll(("(?<!\.\d)(?<=\d)(?=(?:\d\d\d)+\b)"),",");
// yields 1,234.57
  1.  v_MyString = 1234.567
  2.  v_FormattedString = (v_MyString.round(2)).toString().replaceAll(("(?<!\.\d)(?<=\d)(?=(?:\d\d\d)+\b)"),",")
  3.  // yields 1,234.57 

European Decimal Separator and Commas:
copyraw
v_MyString = 1234.567;
v_FormattedString = (v_MyString.round(2)).toString().replaceAll("\.",",").replaceAll(("(?<!,\d)(?<=\d)(?=(?:\d\d\d)+\b)"),".");
// yields 1.234,57
  1.  v_MyString = 1234.567
  2.  v_FormattedString = (v_MyString.round(2)).toString().replaceAll("\.",",").replaceAll(("(?<!,\d)(?<=\d)(?=(?:\d\d\d)+\b)"),".")
  3.  // yields 1.234,57 

Extract URL from a link:
copyraw
v_MyString = "<a href=\"https://www.google.com?searchword=Joe\">Link</a>";
v_FormattedString = v_MyString.replaceAll("^.*href\s*=\s*\"([^\"]*)\".*$","$1");
// yields https://www.google.com?searchword=Joe
  1.  v_MyString = "<a href=\"https://www.google.com?searchword=Joe\">Link</a>"
  2.  v_FormattedString = v_MyString.replaceAll("^.*href\s*=\s*\"([^\"]*)\".*$","$1")
  3.  // yields https://www.google.com?searchword=Joe 

Get first 3 words:
copyraw
v_MyString = "I am Joe the Awesomest";
v_FormattedString = v_MyString.replaceAll("^((?:\S+\s+){2}\S+).*","$1",false);
// yields I am Joe
  1.  v_MyString = "I am Joe the Awesomest"
  2.  v_FormattedString = v_MyString.replaceAll("^((?:\S+\s+){2}\S+).*","$1",false)
  3.  // yields I am Joe 

Not a regular expression but something I use to pad months and dates in a date format:
copyraw
v_MyString = 2;  // February
v_FormattedString = leftpad(toString(v_MyString), 2).replaceAll(" ", "0");
// yields "02"
  1.  v_MyString = 2;  // February 
  2.  v_FormattedString = leftpad(toString(v_MyString), 2).replaceAll(" ", "0")
  3.  // yields "02" 
Category: Zoho :: Article: 681

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF
© 2024 Joel Lipman .com. All Rights Reserved.