/(<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?
/(<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?
 
    
    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.
 
    
    In PCRE, "." does not match every character, it matches every thing that isn't a newline:
Outside a character class, a dot in the pattern matches any one character in the subject, including a non-printing character, but not (by default) newline.
(http://www.php.net/manual/en/regexp.reference.dot.php)
Try something like [\s\S] instead.
 
    
    Because . matches every character except newline by default, unless you feed in the s switch.
See explanation of regex switches here.
In particular
s (PCRE_DOTALL) If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded.
So /(<pre>|<code>|\[code])(.*)(</pre>|</code>|\[/code])/is.
(No g, use preg_match_all).
