Writing a regular expression is usually a trial-and-error process. The process typically goes something like this:
Create a ColdFusion template that contains a string as well as a regular expression to perform the task you want.
Save the ColdFusion template.
Open your web browser, point it to the ColdFusion template, and see if the regular expression behaves as intended.
If the regular expression is successful, great! If not, you have to then modify the regular expression in the template and repeat Steps 2 through 4.
Some regular expressions are simple and can be worked out relatively quickly. Others, however, are more complicated and require you to repeat the trial-and-error process over and over. Constantly having to switch from the browser to the development environment can be a real pain.
With this in mind, let’s look at a ColdFusion-based solution
for building regular expressions. The template in Example 17-2, called
EvaluatorForm.cfm, creates a form for collecting
information about the regular expression you want to test.
Example 17-2. Regular Expression Builder Input Screen
<CENTER> <H2>Regular Expression Builder</H2> </CENTER> <FORM ACTION="Evaluator.cfm" METHOD="POST"> <TABLE> <TR> <TD>String</TD> <TD><TEXTAREA NAME="MyString" COLS="50" ROWS="3"></TEXTAREA></TD> </TR> <TR> <TD>Operation</TD> <TD><SELECT NAME="Operation"> <OPTION VALUE="ReReplace">ReReplace</OPTION> <OPTION VALUE="ReReplaceNoCase">ReReplaceNoCase</OPTION> </SELECT> </TD> <TR> ...