Answer the question
In order to leave comments, you need to log in
How to complete a regular expression?
There is a regular expression that determines if there is an image on the page. '/(img|src)=("|\')[^"\'>]+/im'
How can I fix it so that it detects the presence of two or more pictures? Or get the number of pictures in the text?
Ps you only need to use php.
Answer the question
In order to leave comments, you need to log in
You shouldn't parse HTML with regular expressions .
But if you really want to, in the above case it is correct to use an external calculation of the results of executing a regular expression for this purpose:
$count = preg_match_all('/(img|src)=("|\')[^"\'>]+/im', $html);
if ($count > 1) ...
/<img\s+[^>]*src\s*=[^>]+>/i
Like this, for example:
var q = 0, urls = [];
innerHTML.replace(/\s+/, ' ').replace(/(?:\r|\n|\s)+/, ' ').replace(
/<img(?:.+?)?src=("|')(.+?)\1(?:.+?)?>/i,
function(mtch, q, url) {
urls[q++] = url;
}
);
alert('Картинок - '+q);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question