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
	- v_MyString = "<b>Hello World 123</b>";
 - v_MyFormattedString = v_MyString.replaceAll("[^0-9]","");
 - // 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);
	- 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);
 
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
	- v_MyString = "<b style='color:red'>Hello World 123</b>";
 - v_MyFormattedString = v_MyString.replaceAll("<(.|\n)*?>","");
 - // 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
	- v_MyString = "Hello World 123";
 - v_MyFormattedString = v_MyString.toLowerCase().replaceAll(" ","-");
 - v_MyFormattedString = v_MyFormattedString.replaceAll("[^a-z0-9-]+","");
 - // 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.
	- 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.
 
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
	- v_MyString = "Hello World Hello Joe";
 - v_MyFormattedString = v_MyString.replaceAll("(\b\w+\b)(?=.*\b\1\b)","");
 - // 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:
- v_MyRegEx = "(\/\*([^*]|(\*+[^*\/]))*\*+\/)";
 - v_MyString = "String to output: /* this is a comment */";
 - v_MyFormattedString = v_MyString.replaceAll(v_MyRegEx,"");
 - // 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
	- 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
 
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
	- 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
 
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)))$";
	- // 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)))$";
 
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>
- 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>
 
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]
	- 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]
 
Replace any multiple spaces with a single space:
copyraw
	
v_MyString = "Hello   World!";
v_FormattedString = v_MyString.replaceAll("[ ]+"," ",false); 
// yields Hello World!
	- v_MyString = "Hello World!";
 - v_FormattedString = v_MyString.replaceAll("[ ]+"," ",false);
 - // 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
	- // 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
 
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
	- v_MyString = "Joe's \"Amazing\" Skill & <His> Grunt";
 - v_FormattedString = v_MyString.replaceAll(("([&'\"<>])"),"\\$1",false);
 - // 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);
	- 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);
 
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
	- v_MyString = "PoshDavid Beckham";
 - v_FormattedString = v_MyString.replaceAll("\b(Posh)([^ ]*)","$1 and $2",false);
 - // 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
	- v_MyString = 1234.567;
 - v_FormattedString = (v_MyString.round(2)).toString().replaceAll(("(?<!\.\d)(?<=\d)(?=(?:\d\d\d)+\b)"),",");
 - // 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
	- v_MyString = 1234.567;
 - v_FormattedString = (v_MyString.round(2)).toString().replaceAll("\.",",").replaceAll(("(?<!,\d)(?<=\d)(?=(?:\d\d\d)+\b)"),".");
 - // 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
	- 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
 
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
	- v_MyString = "I am Joe the Awesomest";
 - v_FormattedString = v_MyString.replaceAll("^((?:\S+\s+){2}\S+).*","$1",false);
 - // 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"
	- v_MyString = 2;  // February
 - v_FormattedString = leftpad(toString(v_MyString), 2).replaceAll(" ", "0");
 - // yields "02"
 
Category: Zoho :: Article: 681
	

						  
                
						  
                
						  
                
						  
                
						  
                

Add comment