D
D
Donald_Duck2017-10-07 15:36:16
PHP
Donald_Duck, 2017-10-07 15:36:16

Why doesn't the regular expression find the second match?

$str = '1.9.2017'; // или 10.9.2017 или 1.10.2017
$str = preg_replace('/(^|\.)(\d\.)/', '${1}0$2', $str);
var_dump($str); // 01.9.2017, а ожидалось, что будет 01.09.2017

What am I doing wrong? Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2017-10-07
@Donald_Duck

$str = preg_replace('/(?<=^|\.)(\d\.)/', '0$1', $str);

D
Dmitry, 2017-10-07
@slo_nik

Good afternoon.
Try like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question