x
 
<!DOCTYPE html>
<html>
<body>
<h1>正则表达式修饰符:[0-9]</h1>
<p>在文本 "W3School has been live since 2006" 中,有多少个数字?</p>
<?php
$txt = "W3School has been live since 2006";
$pattern = "/[0-9]/";
echo preg_match_all($pattern, $txt);
?>  
<p>匹配到的位置如下:</p>
<?php
echo preg_replace($pattern, "#", $txt);
?>  
<p>(每个匹配项被替换为 # 字符)</p>
</body>
</html>