dimanche 4 septembre 2016

preg_replace produces unexpected duplicate with a very simple RegEx

var_dump(
  preg_replace('/.?$/s', "x", 'abc'),
  preg_replace('/.$/s',  "x", 'abc')
);

Outputs:

string(4) "abxx" <-- strange, isn't it?
string(3) "abx"

How's that possible?

Aucun commentaire:

Enregistrer un commentaire