As the title says, I am looking for a regex, using php code, that given a $string with line breaks such as the following:
Hello my name is John Doe. Here is a cool video:
embed:http://youtube.com/watch......
I hope you liked it!
It would return:
Hello my name is John Doe. Here is a cool video:
I hope you liked it!
This should do it:
Explanation:
The
/mmodifier enabled multi-line mode (so you can easily match line-based patterns)It matches the start of the line using the caret symbol (anchor):
^Matches the
"embed:stringMatches until the end of the line using
.*Matches any newlines and white spaces after the current line (this cleans up the empty lines better)