O'Reilly logo

Programming ColdFusion by Rob Brooks-Bilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Regular Expression Builder

Writing a regular expression is usually a trial-and-error process. The process typically goes something like this:

  1. Create a ColdFusion template that contains a string as well as a regular expression to perform the task you want.

  2. Save the ColdFusion template.

  3. Open your web browser, point it to the ColdFusion template, and see if the regular expression behaves as intended.

  4. 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> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required