Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 [color="#00FF00"] font mod[/color]
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Sonic
New Member

Germany
82 Posts

Posted - 20 May 2007 :  05:53:57  Show Profile  Visit Sonic's Homepage
servsn i have a question about regex.....

i want to implement a new "forumstag" called -->
[color="#00ff00"]colored text[/color]
for that i use a new function....
as far as it works fine but there is a bug

if someone writes 3 false tags like -->

[color="#00ffsdafasdfasdf00"]colored text[/color]
[color="#00ff00"]colored text[/cafdsafafaolor]
[coadfafaslor="#00ff00"]colored text[/color]


and wirtes after that a right color tag the first wrong tag
will be written in a right html tag and the html font tag will be opend....
so someone can enter some other html tags


is there a better regex or have i wrote an error in the "replace" line?..
thanks in advance for help


function ReplaceFontColor(fString)
Set regEx = New RegExp
regEx.Pattern =  "\[color=("")(\#)([a-fA-F0-9]{6})("")\](.*?)\[/color\]"
regEx.Global = True
Set Matches = regEx.Execute(fString)

if matches.count <> 0 then
	for each match in matches
	changecolor = Replace(Replace(Replace(match.value,"[color=""","<font color="""),"""]",""">"),"[/color]","</font>")
	fstring = Replace(fstring, match.value, changecolor)
	next
end if

ReplaceFontColor = fstring
Set regEx = Nothing
end function

==================================================

a demo of this function is available under
http://sonic.selfip.org
Login: Network
Pass: network

se it under Gästebuch and the link upper left eintragen
click on the blue "B" button for coloring some words...

ich finds genial...
bei uns ist es ratzekuz dunkel und bei dene alle heller nachmittag

Edited by - Sonic on 20 May 2007 06:28:14

HuwR
Forum Admin

United Kingdom
20595 Posts

Posted - 20 May 2007 :  06:26:15  Show Profile  Visit HuwR's Homepage
In the .net version I have done it like this [#000000]some color text[/#000000] if you do it the way you have, you will be unable to nest colors since it will match the wrong closing tag.

the regex code is below (this is for .Net not ASP, but will be similar)


            Regex colourregex = new Regex(@"\[(#[a-fA-F0-9]{2,6})\]");
            MatchCollection MatchList = colourregex.Matches(fString);

            string thismatch;
            foreach (Match m in MatchList)
            {
                thismatch = m.Groups[1].Value;
                fString = Regex.Replace(fString, @"\[(" + thismatch + @")\](.*?)\[\/" + thismatch + @"\]", "<span style='color:$1'>$2</span>", matchOptions);
            }
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.27 seconds. Powered By: Snitz Forums 2000 Version 3.4.07