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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regex Nightmare

Status
Not open for further replies.

webmigit

Programmer
Aug 3, 2001
2,027
0
0
US
Code:
<!-- B,I,U Markup -->
<CFLOOP list=&quot;B,I,U,STRONG,EM&quot; index=&quot;m&quot;>
 <CFSET sig=REReplaceNoCase(sig,&quot;[#chr(91)#](#M#)[#chr(93)#]([^(#chr(91)#b#chr(93)#|#chr(91)#/b#chr(93)#)]*)[#chr(91)#][/](#M#)[#chr(93)#]*&quot;,&quot;<\1>\2</\1>&quot;,&quot;ALL&quot;)>
</CFLOOP>

I'm trying to make the above turn:

Code:
[b]test[/b] this [b]now[/b]
into test this now but all its doing is turning it into: test
Code:
[/b] this [b]
now
Did I help?
Vote!
 
The first thing I'm going to point out is that you can use
Code:
\[
instead of
Code:
#Chr(91)#
to represent a literal opening bracket. I find the former to be much easier to read, and that's how I've written the example below.

My suggestion would be to stop trying to find both start and end tags with separate parts of a single expression. The following code finds either a start or end tag of the specified type, and turns it into its HTML counterpart:
Code:
  #ReReplace(sig,&quot;\[(/?)(b|i|strong|u|em)\]&quot;,&quot;<\1\2>&quot;,&quot;ALL&quot;)#
I used the following string to test it out:
Code:
  test [b]this [[u]not[/u] [i]that[/i]!][/b] thing [strong]now[/strong], and [em]I mean it[/em]!
 
I'm not sure if this id the direction you are going, but you may be interested in this tag:

DP_ParseBBML v1.0
The Depressed Press of Boston

This ColdFusion 4.5+ CFML custom tag translates a simplified, HTML-like markup language called &quot;BBML&quot; into valid HTML. BBML is based on the original UBBCode™ used in the very popular Ultimate Bulletin Board™ discussion application. Useful for online forums or content editing applications this gives end users some of the power of HTML without risking &quot;damage&quot; to the rest of the presentation. - tleish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top