Using regular search for HTML tags with ID attribute

Time:2020-11-22

For example:
String < div style=“ float:left “>123213</div><div>21314423</div>
Mismatch < div > Contents of < / div >

This example can be used to write this example
<[a-zA-Z0-9][^>]+?id=[^>]+?>.*?</div>
matching

The previous PHP example:

Copy codeThe code is as follows:
<?php
$str = ‘<div style=”float:left”>123213</div><div>213123</div>’;
$search = ‘#<[a-zA-Z0-9][^>]+?id=[^>]+?>.*?</div>#is’;
preg_match_all($search,$str,$r);
echo ‘<pre>’;
print_r($r);
echo ‘</pre>’;
?>

This example outputs

Copy codeThe code is as follows:
Array
(
[0] => Array
(
[0] => <div style=”float:left”>123213</div>
)
)