Regular Expression Syntax

Posted on 2004-11-16
Last Modified: 2013-12-24
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?
Question by:shooksm
    LVL 6

    Expert Comment

    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:)
    LVL 9

    Author Comment

    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.
    LVL 15

    Expert Comment

    use an actual space instead of "\s": <cfset VARIABLES.strRECF5 = "<(:alnum:)+ />">

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

    LVL 15

    Accepted Solution

    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>
    LVL 9

    Author Comment

    That works Dan.  Thanks.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
    If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now