content="Wordpress
在以下正则表达式之后我无法匹配空格
$metatag = '<meta name="generator" content="WordPress 4.8.2">';
$metaregex = '/<meta.*?content="Wordpress.(?<version>.*?)"/';
preg_match($metaregex, $metatag, $matches);
print_r($matches);
Run Code Online (Sandbox Code Playgroud)
这是一个错字错误.代替:
$metaregex = '/<meta.*?content="Wordpress.(?<version>.*?)"/';
Run Code Online (Sandbox Code Playgroud)
它应该是:
$metaregex = '/<meta.*?content="WordPress.(?<version>.*?)"/';
Run Code Online (Sandbox Code Playgroud)
注意Word p ress vs Word P ress.
或者您可以使用i
修饰符忽略大小写:
$metaregex = '/<meta.*?content="wordpress.(?<version>.*?)"/i';
Run Code Online (Sandbox Code Playgroud)
i
修饰符:不敏感.不区分大小写的匹配(忽略[a-zA-Z]的情况)