echo preg_replace('/:*$/isD', ':', ':blue:');
A fairly simple PHP regex, which is designed to capture as many colons at the end of a string as possible (there may not be any at all) and replace it with just one. Or at least that's what I set out to do.
Here's the output:
:blue::
I expected, since preg_replace
is greedy, that the colon at the end of the string would be captured, and thus I would get
:blue:
instead.
Oddly, using similar code to check for colons at the beginning of a string (i.e. /^(:)*/isD
) works. I'm guessing this has something to do with the fact that regexes search from left to right, so in the non-working end of string example, it's finding only the end of the string, whereas in the working front of string example, it's already found the beginning of the string.
That said, what I can do to make preg_replace
capture all of the ending colons?