I have a chatterbox and I want to add color codes to the messages.
And it would parse in the real HTMl font color tags. I actually have this working with the following regex.
There is a problem though. It produces icky HTML when there are nested cname tags.
The regex needs to s/// only codes that ARE NOT nested. I am not sure what to do with the following if it happens. Perhaps ignore the s/// altogether? I think that would be best.
Last but not least, I think this is the hard part. I am going over each $name from an array. How would this factor into the regex knowing which are nested tags and which aren't if it can't do them all at the same time?
Code:
[red] Hi there [/red]
[orange] yep [/orange]
And it would parse in the real HTMl font color tags. I actually have this working with the following regex.
Code:
$line =~ s/\[$cname\](.+?)\[\/$cname$\]/<font color="$ccolor">$1<\/font>/gi;
There is a problem though. It produces icky HTML when there are nested cname tags.
Code:
[purple] test [orange] text [/orange] [/purple]
becomes
<font color="purple"> test <font color="orange"> test </font> </font>
The regex needs to s/// only codes that ARE NOT nested. I am not sure what to do with the following if it happens. Perhaps ignore the s/// altogether? I think that would be best.
Code:
[yellow] Hi [blue] there [/yellow] [/blue]
Last but not least, I think this is the hard part. I am going over each $name from an array. How would this factor into the regex knowing which are nested tags and which aren't if it can't do them all at the same time?
Code:
foreach my $line (@keep) # @keep holds all messages
{
foreach my $color (@colors) # colors holds the color codes
{
my ($cname, $ccolor) = split(/<!!>/, $color);
$line =~ s/\[$cname\](.+?)\[\/$cname$\]/<font color="$ccolor">$1<\/font>/gi;
}
}