[thelist] Perl Regex

Matthew Fischer mfischer at e-fishsolutions.com
Tue Apr 3 23:38:00 CDT 2001


On 4/4/01 at 9:29 AM, Manish Sharma <msharma at satyam.net.in> wrote:

> What's the best Perl Regex that matches HTML tags in a line?


$string = "<TITLE>Test title</TITLE>";
$string =~ s/<[^>]+>//g;
print "$string";

Result:
   "Test title"

The expression matches all occurrences of a "<", followed by one or more characters that aren't a ">", followed by a ">". If you don't have the "g" at the end, it will only match the first occurrence.




More information about the thelist mailing list