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

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

高洛峰
Release: 2017-01-22 14:06:35
Original
1594 people have browsed it

For example:
String

123213
21314423

Does not match the content of
...


To write this example, you can use
<[a-zA-Z0-9][^> ]+?id=[^>]+?>.*?

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;
'; ?>
Copy after login

This example output

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

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!

Related labels:
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template