Tuesday, February 3, 2009

Using REGEX in ColdFusion

I had to do a password validation in ColdFusion and learnt a few functions of regular expressions in ColdFusion.

REFind – Used to check if a particular string confines to a regular expression. If the string is in the regex format mentioned it returns the starting location of the REGEX of that string.

REFind("regular expression", "String", "returns")
REReplace – Used to replace the particular regular expression in a string.
REReplace("String", "regularExpression", "SubString", "Scope")
Where scope is : one – change the first occurrence of the regex, all – change all the occurrences.

ColdFusion has a set of character classes defined which can be used instead of creating the regular expressions explicitly.

:alpha: All alphabets is equivalent to [A- Z][a- z] . The set of all character classes can be found here at the very end.

No comments: