Why a regular expression does not find a second hit?

$str = '1.9.2017'; // or 10.9.2017 or 1.10.2017
$str = preg_replace('/(^|\.)(\d\.)/', '${1}0$2', $str);
var_dump($str); // 01.9.2017, and it was supposed to be 01.09.2017

What am I doing wrong? Thanks in advance!
June 14th 19 at 19:10
2 answers
June 14th 19 at 19:12
Solution
$str = preg_replace('/(?<=^|\.)(\d\.)/', '0$1', $str);
Thank you! - derek_Graham commented on June 14th 19 at 19:15
And that's about it <= in the regular season to read? - derek_Graham commented on June 14th 19 at 19:18
, php.net/manual/ru/reference.pcre.pattern.syntax.php - Kenyatta commented on June 14th 19 at 19:21
June 14th 19 at 19:14
Good afternoon.
Try so
commented line is not readily visible. Just write text, so it will be noticeable - aniya commented on June 14th 19 at 19:26
For the examples not working - https://regex101.com/r/puiY3N/2 - derek_Graham commented on June 14th 19 at 19:17
then you should give a few options instead of one, then to not write "not working".
Full-time teller in holiday, where all know what You really need.
another option - derek_Graham commented on June 14th 19 at 19:20
Does not work.

so it is necessary to give a few options instead of one

Like in the code in the comments the other options indicated)) - Kenyatta commented on June 14th 19 at 19:23

Find more questions by tags PHPRegular expressions