--As off Thursday, November 27, 2003 7:42 PM -0500, Dan Anderson is alleged to have said:
So what am I doing wrong and how do I make a case insensitive tr/// regexp?
Thanks for your help,
--As for the rest, it is mine.
You can't make a case insensitive tr/// regexp: tr/// doesn't do regexp. It does transliteration: it replaces the characters in the first part with the respective ones in the second part.
You want the s/// operator: s/\<font.*\>//i
--As for the rest, it is mine.
Hold on one moment before you shoot yourself in the foot with that loaded gun I just gave you...
You definitely need the s/// operator, (unless you can use one of the HTML parsing modules). But let's fix that regrexp first, shall we?
First off, you may have noticed I removed the first '.*' from your regrexp: that's because nothing is allowed between the opening '<' and the name of the element. Unless, of course, it is a closing tag, in which case you have a '/' in there. So, that would be:
s/\<\/?font.*\>//i
Just a moment, that's ugly. Substitution allows different dividers, let's use something else. I'll use '[' and ']'. So, re-written that as:
s[\</?font.*\>][]i
(Note that we've dropped the escape on the slash: it is no longer needed.)
Ok, let's try that. Yikes!!! It matches _everything_ after the first font tag!! Um, that greedy '.*' needs to be fixed, to stop as soon as it can instead of matching as much as it can. We do that by adding a '?' after it:
s[\</?font.*?\>][]i
There, that's better. Oh, but there is one other problem: '.*?' stops at a newline. That may sound fine, but a newline is legal inside a HTML element tag... We change this by adding a 's' with the 'i' modifier:
s[\</?font.*?\>][]si
That should work. Of course, it only changes the first font tag it finds... To fix that we need another modifier: 'g'. So the final pattern is:
s[\</?font.*?\>][]gsi
I think that covers everything... And it is a quick lession is why we usually tell people not to try matching HTML with regrexps.
Daniel T. Staal
--------------------------------------------------------------- This email copyright the author. Unless otherwise noted, you are expressly allowed to retransmit, quote, or otherwise use the contents for non-commercial purposes. This copyright will expire 5 years after the author's death, or in 30 years, whichever is longer, unless such a period is in excess of local copyright law. ---------------------------------------------------------------
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]