M
M
modesden2016-06-06 17:19:15
PHP
modesden, 2016-06-06 17:19:15

Why does the regular expression take the last occurrence of a substring and not the first?

Please help me. It is necessary to write a regular expression so that it selects what begins with INSERT INTO, then anything (including line breaks) and ends with the first occurrence of ');' .
Here's what I made.
$result = preg_match_all("/INSERT INTO(.|\n|\r)*\)\;/i", $content, $inserts);
but it doesn't work like that. Selects from INSERT INTO until the last ');' , and it is necessary to the first.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DTX, 2016-06-06
@modesden

You are just lazy.
And they must be greedy.
https://learn.javascript.ru/regexp-greedy-and-lazy
U (ungreedy) flag to help
https://regex101.com/r/nK7aV6/1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question