This is just a short note about how to use RegEx in ColdFusion Builder to help with code migration. Today I am working with an old ColdFusion 4.5 site and I'm putting it on CF8. At CFWebtools, we believe in helping ColdFusion stay ColdFusion by upgrading to newer versions! The good news is there are no C++ CFX tags to worry about. However, there is a lot of code using the deprecated "ParameterExists()" function. This should be updated to isDefined("...").

view plain print about
1<!--- snip of CF 4.5 code --->
2<CFIF NOT ParameterExists(session.GUID)>
3    <CFIF ParameterExists(COOKIE.GUID)>
4        <CFSET session.GUID = COOKIE.GUID>
5    <CFELSE>
6        <CFPARAM name="session.GUID" default="#CreateUUID()#">
7        <CFCOOKIE domain=".example.com" expires="NEVER" name="GUID" value="#session.GUID#">
8    </CFIF>
9</cfif>

Homesite and CF Studio hade a really nice RegEx Search Replace across all documents function. ColdFusion Builder 1 has an even nicer one. (and from what I see ColdFusion Builder 2 version is even better).

Use ctrl+h to launch the search dialog. Here is what you'll see.

The features I like best are the ability to do RegEx and the ability to search on a selected Working Set.

After entering the RegEx to find all the ParameterExists just click on the Replace button. Trust me and just do it. Nothing bad will happen. At this point ColdFusion Builder does a search to find all the instances that matches and then gives you a dialog box where you get to enter the replace string. Also, a really nice feature is that it lets you preview the changes it's about to make via a full side by side DIFF comparison. This is the part that makes ColdFusion Builders version far better that what we had in Homesite. I get to fully preview and know ahead of time what is about to get replaced or totally munged beyond all belief and say Cancel this let me try something else. This screen shot shows what I am talking about.

So once we are ready and approve of the change simple click OK. That's it, all done.

I did find out a couple of other things while I tried to recreate what I did to write this blog post.

  1. I was able to fully "Undo" my sweeping changes with ctrl+z
  2. I was also able to "Redo" them as well.
  3. If your original search string finds nothing a dialog box will inform you of that and not let you continue

So what was the RegEx?

view plain print about
1(ParameterExists\()([^\)]*)
2
3isDefined("$2"

Very basic RegEx, it finds two groups, and replaces the first group with isDefined(" the appends the second group with a trailing ".

I hope this helps people understand a great feature in ColdFusion Builder and how it can help you migrate old ColdFusion code to newer versions.