Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expressions. Need help 1

Status
Not open for further replies.

noyes99

Programmer
Jun 25, 2002
38
IN
I am looking for some help with a regular expression. I have a scenarios, where I have strings, with <table> within <table> tags within them. I need to replace the outermost table tags with <pre><table>. How do I write this reg ex. What I am thinking of doing is this.

Take a string. Replace the inner tables with a @@@TABLEOPEN@@@ and @@@TABLECLOSE@@@ then replace all the table tags with <pre><table> and then replace the placeholder with <table>

ie. I would want
EGYEYUGEYUEUYEY<table cellpadding="23"><tr><td><table cellspacing="23"><tr><td>HGDHDHDJK</td></tr></table></td></tr></table>EGYEYUGEYUEUYEYEGYEYUGEYUEUYEY

with

EGYEYUGEYUEUYEY<pre><table cellpadding="23"><tr><td><table cellspacing="23"><tr><td>HGDHDHDJK</td></tr></table></td></tr></table></pre>EGYEYUGEYUEUYEYEGYEYUGEYUEUYEY

Any help would be appreciated
 
Code:
<Cfset mystring="EGYEYUGEYUEUYEY
<table cellpadding=""23"">
  <tr><td>
      <table cellspacing=""23"">
        <tr><td>
            HGDHDHDJK</td></tr>
      </table>
  </td></tr>
</table>
EGYEYUGEYUEUYEYEGYEYUGEYUEUYEY">

<cfset mystring=Replace(mystring,"<table","<pre><table")>
<cfset mystring=Replace(Reverse(mystring),">elbat/<",">erp/<>elbat/<")>
<cfset mystring=Reverse(mystring)>

<cfoutput>#mystring#</cfoutput>

I'm thinking the above should work..

It:

. replaces the first instance of table with pre table
. replaces the last instance of /table with /pre /table by reversing the string and replacing the first instance.
. Re-reverses the string making for the orignal order
. hurts my head to type backwards like that :)

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top