Joe Simes
Joe Simes

Reputation: 124

Replace single quotes with double quotes in tags only! Using ColdFusion regex

I only see PHP solutions to this problem.

Basically I need to go from:

<TEXTFORMAT LEADING='2'><P ALIGN='LEFT'><FONT FACE='Verdana' style='font-size:10' COLOR='#0B333C'>My name's Mark</FONT></P></TEXTFORMAT>

to this:

<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" style="font-size:10" COLOR="#0B333C">My name's Mark</FONT></P></TEXTFORMAT>

Using ReReplaceNoCase but ... yup you guessed it .. I suck at regular expressions! :)

Upvotes: 0

Views: 1015

Answers (1)

Jake Feasel
Jake Feasel

Reputation: 16955

Rather than use a regex, you can do what you need in this case by letting CF do the work for you, via XML parsing libraries:

<cfsavecontent variable = "origStr">
    <cfoutput>
        <TEXTFORMAT LEADING='2'><P ALIGN='LEFT'><FONT FACE='Verdana' style='font-size:10' COLOR='##0B333C'>My name's Mark</FONT></P></TEXTFORMAT>
    </cfoutput>
</cfsavecontent>
<cfset xmlString = ToString(xmlParse(origStr))>

<cfdump var="#xmlString#">

Which will get back:

<?xml version="1.0" encoding="UTF-8"?> <TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT COLOR="#0B333C" FACE="Verdana" style="font-size:10">My name's Mark</FONT></P></TEXTFORMAT>

If that leading <?xml...> annoys you, you can cut that part off:

<cfdump var="#Right(xmlString, Len(xmlString) - 40)#">

Upvotes: 1

Related Questions