Link to home
Start Free TrialLog in
Avatar of shooksm
shooksm

asked on

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:

<data></data>

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:

<(\w)+\s/>

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

<(:alnum:)+\s/>

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:

<tag></tag>

Here is a quick test page I threw together:

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

Anyone have ideas on where I am going wrong with the expression?
Avatar of mosphat
mosphat

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:)
Avatar of shooksm

ASKER

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 = "<[^>]*/>">

ASKER CERTIFIED SOLUTION
Avatar of danrosenthal
danrosenthal

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shooksm

ASKER

That works Dan.  Thanks.