P
P
Pavel Sidorov2021-07-04 01:31:56
PHP
Pavel Sidorov, 2021-07-04 01:31:56

Why does the regex only capture the first element?

text:

Number 560
Size range: 42 88,44,46
# Price: 400 rubles 400 kop. PCS.
Location: 2A-75 block A

/(?<=ряд:\s)(?:\d+)/gm

outputs only 42 , but I need to capture all numbers until the end of the line
42
88
44
46

explain plz

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2021-07-04
@pavel__sidorov

$str = 'Число 560
Размерный ряд: 42 88,44,46
#Цена: 400 руб 400коп. шт.
Место: 2А-75 корпус А';

preg_match('/ряд:.+/', $str, $m);

preg_match_all('/\d+/', $m[0], $r);

print_r($r[0]);

Or
preg_match_all('/(?:\G(?!^)|ряд:)[\s,]\K\d+/', $str, $r);

https://regex101.com/r/aMEAGG/1

A
Antonio Solo, 2021-07-04
@solotony

so
/(?<=ряд:\s)(?:\d+)(?:[^\d]+\d+)*/gm
what kind of result are you expecting?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question