php REGEX 匹配某一行之后的每一行
可能的重复:
PHP REGEX preg_math_all 特定行之后的每一行< /a>
我想要一个匹配特定行之后的每一行的模式 - 我可以依赖的唯一常量是,如果标题在那里,我知道我想要跟随行。如果我最终得到的行数比我想要的多也没关系,因为我只会取第一个,无论我需要多少行。
SURGICAL/MEDICAL HISTORY <--Header to indicate the beginning of my list
HISTORY 1 <--line1 to be matched
HISTORY 2 <--line2 to be matched
HISTORY 3 <--line3 to be matched
.
.
我不会发布文本的真实示例,因为这并不重要 - 模式必须灵活并且出于其他特殊原因。我总是对正则表达式中的行有这样的问题。这就是我所拥有的:
$ptn = "/SURGICAL\/MEDICAL HISTORY\s*(^(.+)$)+/m";
但这只匹配第一行。谢谢!
编辑:我需要将所有匹配的行分隔在一个数组中:
Array
(
[0] => Array
(
[0] => SURGICAL/MEDICAL HISTORY
HISTORY 1
HISTORY 2
)
[1] => Array
(
[0] => HISTORY 1
[1] => HISTORY 2
)
)
Possible Duplicate:
PHP REGEX preg_math_all every line after a particular line
I want a pattern that will match every line after a particular line - the only constant that I can rely on is that if the header is there I know I want the follow lines. It doesn't matter if I end up getting more lines than I want because I'll only take the first however many I need.
SURGICAL/MEDICAL HISTORY <--Header to indicate the beginning of my list
HISTORY 1 <--line1 to be matched
HISTORY 2 <--line2 to be matched
HISTORY 3 <--line3 to be matched
.
.
I'm not posting a real sample of the text because it shouldn't matter - the pattern must be flexible and for other particular reasons. I just always have such an issue with lines in regex. Here is what I have:
$ptn = "/SURGICAL\/MEDICAL HISTORY\s*(^(.+)$)+/m";
But that only matches the first line. Thanks!
EDIT: I need all of the matched lines in separated in an array:
Array
(
[0] => Array
(
[0] => SURGICAL/MEDICAL HISTORY
HISTORY 1
HISTORY 2
)
[1] => Array
(
[0] => HISTORY 1
[1] => HISTORY 2
)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能有用:模式修饰符
您的最终正则表达式应如下所示(未经测试):
This might be useful : Pattern Modifiers
Your final regex should look like this (not tested) :