[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

Regular Expression Syntax

We are converting some application servers over from CF5 to CFMX and have run into some issues with the way CFMX generates WDDX packets differently then CF5.  This is causing a problem with some servers that share the WDDX packet using a central database.  The problem arises when an element of a structure has no value.  CF5 creates the node as:


While CFMX creates the node as:

<data />

The problem is that CF5 does not recognize the single tag syntax and bombs out.  I was working on a Regular Expression to find these single tags.  The following works in VB:


And because I need it to work on CF5 I tried using the character classes:


Neither work.  But basically, I want to find any tag in the format of:

<tag />

So I can replace it with the tag in the format of:


Here is a quick test page I threw together:

<cfsavecontent variable="VARIABLES.strBadWDDX">
      <data />
      <data with="attribute" />
      <goodData with="attribute">data</goodData>
<cfset VARIABLES.strRE = "<(\w)+\s/>"><!--- Good Expression that works in VB --->
<cfset VARIABLES.strRECF5 = "<(:alnum:)+\s/>"><!--- <(:alnum:)+\s/> --->
            <title>WDDX Tag Fix</title>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
            <p>Match Found = #YesNoFormat(REFind(VARIABLES.strRECF5, VARIABLES.strBadWDDX))#</p>
            <p>Index = #REFind(VARIABLES.strRECF5, VARIABLES.strBadWDDX)#</p>

Anyone have ideas on where I am going wrong with the expression?
  • 2
  • 2
1 Solution
You typed <data/> in your example. It has no whitespace, so the regex should be <(\w)+\s?/>
BTW, \w is recognized by CFMX as well. No need for (:alnum:)
shooksmAuthor Commented:
The problem is not on CFMX it is in CF5 as I stated above.  CF5 will not recognize the single closed tag format of <tag />.  The example without the space was just to test the regular expression to make sure it was only grabbing the tag with a space.
use an actual space instead of "\s": <cfset VARIABLES.strRECF5 = "<(:alnum:)+ />">

But, this might work better...
<cfset VARIABLES.strRECF5 = "<[^>]*/>">

oops, :alnum: does not work for me either...but changing to REFINDNOCASE and "a-z0-9" works:

<cfset VARIABLES.strRECF5 = "<([a-z0-9])+ />">
<p>Match Found = #YesNoFormat(REFindnocase(VARIABLES.strRECF5, VARIABLES.strBadWDDX))#</p>
shooksmAuthor Commented:
That works Dan.  Thanks.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now