I'm trying to match all lines in a string which start and end with a vertical bar "|". I have tried out different patterns and tested the pattern '/^\|.*\|$/m' successfully using the online tester https://regex101.com/.
However, when I put the same successfully tested pattern into my php script, it does not work. This is a sample code:
$re = '/^\|.*\|$/m';
$str = 'Why is this not working?
|Test|
|Test|
|Test|
|Test|
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
var_dump($matches);
This code outputs
array(0) {
}
which means the pattern did not find any match. It is driving me crazy. What am I doing wrong?