The best match for /?
|
?/
on "
"
is the substring consisting of the first character only (the
). This is because the regex engine tries to find a match for /?
/
before it starts looking for a match for /
?/
.* This is always true for |
matches: a match for the part of the regex before the |
takes precedence over a match for the regex after it.
And so, having found its first match, it continues from where it left off and discovers that the next character also matches the regex. That's 2 matches, each of which is replaced by a "<br />"
.
Try doing /
?|
?/
instead.
*(More precisely, it looks for matches for /?
/
anchored at the start of the string before searching for matches for /
?/
anchored at the start; only if these searches fail does it start looking for matches anchored later in the string.)