multiline regular expression

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
gobezu
Forum Newbie
Posts: 1
Joined: Sat Feb 11, 2006 11:53 am

multiline regular expression

Post by gobezu »

i am trying to match ALL div's in a html page, including those spanning over several lines with the following regular expression but fails

Code: Select all

/<(div)[^>]*?(>.*?<\/\1>|\/>)/im
please help me detect what could be wrong with this one
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Are you trying to match the div and all its contents, or just the div start tag?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The pattern would suggest entire divs. The "m" will only allow single lines however. "s" would span across multiple lines.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post by Mordred »

You need to consider whitespace between the HTML syntactic chars, for example, this is valid HTML:

Code: Select all

<     div   class    =  "blah"   >  content  <   /   div   >
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

What are you trying to to exactly? Also, what language? php? javascript?
Post Reply