Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Trying to get a regex to match some very simple HTML. I know regexing html isn't the best idea but this one is simple (if you're good at regexes) and the html wont fluctuate.
cingular">text to match here </font> </b><br> <br> all of this stuff no matter what BR tags or whatever is found should be matched </p>
I need two vars, $1 and $2 for this $content. I want to match the top text into 1 and everything after the first BR to the NEXT

it finds. There will never be a premature

tag so I want everything out of there to be in $2.

This is my attempt

$content =~ m#cingular">(.+?)<\/font>\s*<\/b><br>(.+?)<\/p>#xi;

Replies are listed 'Best First'.
Re: small regex
by davidrw (Prior) on Jul 01, 2006 at 00:48 UTC
    You're close -- you need the /s modifier (see perlre) so it matches through newlines .. (note also that your /x is unnecessary in this case). Working example:
    my $content = do {local $/=undef; <DATA>}; $content =~ m#cingular">(.+?)<\/font>\s*<\/b><br>(.+?)<\/p>#si; use Data::Dumper; print Dumper [$1, $2]; __DATA__ cingular">text to match here </font> </b><br> <br> all of this stuff no matter what BR tags or whatever is found should be matched </p>
Re: small regex
by TedPride (Priest) on Jul 01, 2006 at 00:51 UTC
    use strict; use warnings; $_ = join '', <DATA>; my ($first, $second) = m|cingular">(.*?)</font> </b><br>\n<br>\n(.*)|s +i; __DATA__ cingular">text to match here </font> </b><br> <br> all of this stuff no matter what BR tags or whatever is found should be matched