Menu
I am trying to write a regex which will recognize a block of text as being composed of plain text and HTML Comments. The regex I have so far is as follows:
[code=php]$pattern = “/(?P<text>.*?)(<!–(?P<comment>.*?)–>)?/sm”;
What I want is to get the first chunk of text into the back-reference <text> and get the text of the comment into the back-reference <comment>. I made <text> lazy, because it tries to take the comment also otherwise, and I made <comment> optional because it will not always be there. The problem, is that will this combination, it now captures nothing.
I cannot figure this out. Can anyone help?