I'm writing a regex to parse markdown admonitions. Here's my test data:
!!! hello
This is a test
with multiple lines
!!!
However, instead of capturing "hello", my code seems to be capturing "hello\r\n" and for the life of me I can't figure out why.
Here's some simplified PHP code exhibiting the issue I'm encountering:
preg_replace('/^!!! (.*)/m', '|$1|', $content);
This replaces the first line of the test data with:
|hello
|
Where the second pipe is on the next line.
When I modify this regex like so:
preg_replace('/^!!! ([a-z]*)/m', '|$1|', $content);
Then I get the expected output for the first line:
|hello|
In multiline mode, the . character is not supposed to match line breaks -- so where is the line break coming from in my capture group that uses the dot?
A few other things I tried:
preg_replace('/^!!! (.*o)/m', '|$1|', $content);
works as expected.
preg_replace('/^!!! (.*)$/m', '|$1|', $content);
still contains the line break, even though I thought $ should be matching before the line break.
I've been trying to figure this out for hours and am clearly missing something (probably obvious). I've also scoured the internet and stackoverflow looking for clues but have come up empty.
Any and all help appreciated. Thanks!