匹配空格或换行符[重复]

问题描述 投票:0回答:1

我正在使用以下代码远程检查WordPress版本。

preg_match('/<meta name="generator" content="WordPress (\d+(\.\d+)*)"/i', $html_content, $matches);

如果网站的元标记位于同一行,则 preg_match 将返回找到的匹配项。这很好。

<meta name=generator content="WordPress 6.4.1">

如果网站的元标记不在同一行,preg_match将返回未找到匹配项。

<meta
name=generator content="WordPress 6.4.1">

我该如何解决这个问题?

php regex preg-match newline whitespace
1个回答
0
投票

您可以尝试使用 \s 字符。

\s 字符类将匹配任何空白字符,包括空格、制表符和换行符。

例如:

/<meta\s+name=generator\s+content="WordPress\s+(\d+(\.\d+)*)"/i
© www.soinside.com 2019 - 2024. All rights reserved.