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

x
  • 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:

<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?
0
shooksm
Asked:
shooksm
  • 2
  • 2
1 Solution
 
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
 
shooksmAuthor Commented:
That works Dan.  Thanks.
0

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