Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex - Why doesn't this .* (dot-star) match line-breaks? [duplicate]

/(<pre>|<code>|\[code])(.*)(</pre>|</code>|\[/code])/gi

This works if I have something such as:

<code>foobar</code>

But if I were to have a line-break like this:

<code>
    Awesome
</code>

It will not match it, what am I doing wrong?

like image 622
daryl Avatar asked Jan 19 '12 00:01

daryl


1 Answers

You do need the DOTALL modifer /s, because the . dot per default excludes linebreaks. The /g modifier OTOH is not legal in PHP and PCRE.

You should also use .*? to not match too wide.

like image 130
mario Avatar answered Sep 19 '22 23:09

mario