Page 1 of 1

multiline regular expression

Posted: Wed Jan 17, 2007 5:45 pm
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

Posted: Wed Jan 17, 2007 8:29 pm
by Ambush Commander
Are you trying to match the div and all its contents, or just the div start tag?

Posted: Wed Jan 17, 2007 9:50 pm
by feyd
The pattern would suggest entire divs. The "m" will only allow single lines however. "s" would span across multiple lines.

Posted: Thu Jan 18, 2007 4:56 am
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   >

Posted: Thu Jan 18, 2007 5:38 am
by Kieran Huggins
What are you trying to to exactly? Also, what language? php? javascript?