M
M
My joy2018-02-02 18:16:14
Regular Expressions
My joy, 2018-02-02 18:16:14

Why does the regular expression only find the last match?

Hi friends.
I'm trying to pull out the text of the links that are in the cells of the table. But preg_match_all gives me only the last match, but I need the whole list.

$content = '<tr>sdf<td><a class="123">777777</a></td><td></td><td><a class="123">888888</a></td></tr>';
$pattern = '~<td><a.*>([0-9]{5,})<\/a><\/td>~mui';
preg_match_all($pattern, $content, $matches); // находит только 888888

What did I write wrong in the regular expression?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nick Sdk, 2018-02-02
@t-alexashka

$pattern = '~<td><a.*?>([0-9]{5,})<\/a><\/td>~mui';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question