符号意义
定义字符集
[a-z]
[a-zA-Z]
特殊字符集
$c
^
.
*
?
\+
a|b
组合字符
\d
\D
\w
\W === [^A-Za-z0-9_]
\s
\S
\b 匹配边界
\B 非单词边界
{5} 钱一个单元严格出现5次
{m,n} 至少m至多n
[^abc]不是括号内任意字符
\w
子表达式
(.*?)
preg_match()匹配
<?php
header("Content-type:text/html;charset=utf-8");
$str="https://www.51cto.com/";
$strall=file_get_contents($str);
$preg="/<a href=\"http://os.51cto.com/art/(.*?)\" target=\"_blank\">(.*?)</a>";
$res=preg_match_all($preg, $strall, $out);
var_dump($res);
本文详细介绍了正则表达式的各种符号及其意义,包括基本字符集、特殊字符集、组合字符等,并通过一个PHP示例展示了如何使用preg_match()函数从网页内容中提取特定信息。
2340

被折叠的 条评论
为什么被折叠?



