troubles matching multiline HTML chunk

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

Moderator: General Moderators

Post Reply
User avatar
pedrotuga
Forum Contributor
Posts: 249
Joined: Tue Dec 13, 2005 11:08 pm

troubles matching multiline HTML chunk

Post by pedrotuga »

I want to match this:

Code: Select all

 
<!-- THE BEGINNING -->
<div class="whatever">
<p>Some <u>Random</u> HTML in here</p>
</div>
<!-- THE END -->
 
This is the regex i thought of but it doesn't match anything... why?

Code: Select all

|<!--\sTHE\sBEGINNING\s-->.*?<!--\sTHE\sEND\s-->|m
User avatar
ridgerunner
Forum Contributor
Posts: 214
Joined: Sun Jul 05, 2009 10:39 pm
Location: SLC, UT

Re: troubles matching multiline HTML chunk

Post by ridgerunner »

Because you need to set the 's' single-line mode, or "dot matches newline mode". The 'm' multi-line mode only affects how the '^' and '$' match or don't match at newlines. Otherwise your regex looks just fine.
Post Reply