Home  >  Article  >  Web Front-end  >  Use regular expression to find html tags with id attribute in html

Use regular expression to find html tags with id attribute in html

高洛峰
高洛峰Original
2017-01-22 14:06:351470browse

For example:
String8e62618ac3ec95641599edb0d182503812321316b28748ea4df4d9c2150843fecfba68c53114d76b92ed7373f1c8f5d2221d192131442316b28748ea4df4d9c2150843fecfba68
Does not match the content of c53114d76b92ed7373f1c8f5d2221d19...16b28748ea4df4d9c2150843fecfba68

To write this example, you can use
bf25faba508d5088b42ea98f8e3d0399 ]+?id=[^>]+?>.*?16b28748ea4df4d9c2150843fecfba68
Match

Previous php example:

<?php 
$str = &#39;<div style="float:left" id="ab">123213</div><div class="a123">213123</div>&#39;; 
$search = &#39;#<[a-zA-Z0-9][^>]+?id=[^>]+?>.*?</div>#is&#39;; 
preg_match_all($search,$str,$r); 
echo &#39;<pre class="brush:php;toolbar:false">&#39;; 
print_r($r); 
echo &#39;
'; ?>

This example output

Array 
( 
[0] => Array 
( 
[0] => <div style="float:left" id="ab">123213</div> 
) 
)

For more articles related to using regular expressions to find html tags with id attributes in html, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Basic use of swiper (19)Next article:Basic use of swiper (19)