我需要匹配所有以正则表达式开头的行。样本输入。
#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