警告:preg_match():编译失败:在偏移量 6 处没有可重复的内容
Warning: preg_match(): Compilation failed: nothing to repeat at offset 6
我想用正则表达式解析以下文档块/评论。下面的代码
$subject = <<<HTML
/**
Theme Name: Hello world
*/
HTML;
$pattern = '/^\/(?:*)+Theme Name:(\s)?([\w]+)/';
preg_match($pattern, $subject, $matches);
print_r($matches);
运行代码输出如下错误..
Warning: preg_match(): Compilation failed: nothing to repeat at offset 6 in C:\xampp\htdocs\blog\test.php on line 11
*
中的(?:*)
表示0次或多次。
你是说 \*
吗?
https://www.regex101.com/r/vH7lB3/1
注意我在Theme
之前也加了\s*
来匹配换行符和空格
我想用正则表达式解析以下文档块/评论。下面的代码
$subject = <<<HTML
/**
Theme Name: Hello world
*/
HTML;
$pattern = '/^\/(?:*)+Theme Name:(\s)?([\w]+)/';
preg_match($pattern, $subject, $matches);
print_r($matches);
运行代码输出如下错误..
Warning: preg_match(): Compilation failed: nothing to repeat at offset 6 in C:\xampp\htdocs\blog\test.php on line 11
*
中的(?:*)
表示0次或多次。
你是说 \*
吗?
https://www.regex101.com/r/vH7lB3/1
注意我在Theme
之前也加了\s*
来匹配换行符和空格