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?
LVL 9
shooksmAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mosphatCommented:
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:)
0
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.
0
danrosenthalCommented:
use an actual space instead of "\s": <cfset VARIABLES.strRECF5 = "<(:alnum:)+ />">

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

0
danrosenthalCommented:
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>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shooksmAuthor Commented:
That works Dan.  Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.