Home: Perl Programming Help: Regular Expressions:
HTML Tag Regex.

New User

Apr 16, 2007, 7:07 PM

Views: 6963
HTML Tag Regex.

I have been away from perl for a while and am stuck on the following:

I have a html string. Somewhere in the string there will be one or more sets of <DIV> and </DIV> tags. I need a regex that will grab the outer most opening and closing tags and all the content between them.

eg :

"<FONT face=Tahoma size=2>
<DIV>The first message...</DIV>
<DIV>The second message....</DIV></FONT>"

I want to capture :

<DIV>The first message...</DIV>
<DIV>The second message....</DIV>

Any help would be great, Thank you.


Apr 19, 2007, 11:15 AM

Views: 6958
Re: [reder] HTML Tag Regex.

As far as I know,


should work. $2 will contain everything within the two div tags.

You can also use the HTML::Parser module to this effect.

Need some real-time help? Shove admin@ub3r.net on yer MSN.

(This post was edited by osmodius on Apr 19, 2007, 11:22 AM)