I’m trying to match this block here
/code\
int foo(string $bar, int $bleh); Simple function!
bool is_even(mixed $var); Checks if a variable is even.
\code/
my pattern is "/code\\(.*?)\code/"
yet no matches found!
Okay it’s very hard to show what I mean in stackoverflow due to all the restrictions on html.
But code tags are basically HTML tags with opener and closer tag.
does regex not handle multiple lines? yes I do have multi-line flag triggered
Thanks
In most regex implementations,
multi-linemode with themmodifier does not let the.match line breaks, but causes the^to match the start of a line and the$match the end of a line.What you need is to enable
dot-allmode by adding thesmodifier. And if your language’s regex implementation does not support that modifier (JavaScript does’t, if memory serves me right), you can mimic this using[\s\S]instead of.(DOT).Be aware that you will get in trouble matching stuff like:
nested tags:
(matched text:
/code\ /code\ ... \code/)or commented tags:
(matched text:
/code\ ... <!-- \code/)