【发布时间】:2013-08-03 04:25:40
【问题描述】:
我需要匹配所有以正则表达式开头的行。示例输入。
#X0 alpha numeric content that I want
#X1 something else
#X26 this one as well
除了第一行之外,这两个正则表达式都有效。我需要匹配所有 #X\d{1,2} 行。
/^(\#X\d{1,2}\s+)(.*?)$/m
/^(\#X\d{1,2}\s+)(.+)*$/m
我用上面的任何正则表达式得到了什么。
$pattern= "/^(\#X\d{1,2}\s+)(.+)*$/m";
preg_match($pattern, $content, $match);
echo $match[1];
alpha numeric content that I want
期望的输出。
alpha numeric content that I want
something else
this one as well
【问题讨论】:
-
抱歉,不清楚您在问什么。你能详细说明一下吗?此外,不清楚为什么第二个正则表达式是相关的,因为它涉及以“#O”开头的行,这在您的示例中不存在。