我有 100+ 个文本文件,其中包含以下格式的文本。
Some Clutter...
This text file is written by using GuavaSoft Notepad.
some more info
Required Info: some text here, some text here also, a new line
text on another new line, SOME CAPITAL TEXT, one more new line,
some numbers, some punctuation marks,
some completely empty line to follow
some empty lines with tab-spaces, spaces to follow
ok, this is the end of required info..
some more unnecarry lines
empty line
etc
etc
我需要捕获/获取"所需信息"和"信息.."之间的所有文本,跨越多行。
我正在将所有文件读入$str。我提出的正则表达式是
$pattern = "/Required Info(.+?)info'.'./im";
preg_match($pattern, $str, $matches);
print_r($matches);
现在,这在 http://rubular.com/r/sP26IahrgI 工作,但在我自己的本地XAMPP上不起作用。 $matches只是显示空的。
我对正则表达式很陌生,并试图一起学习。我的正则表达式有误吗?
您需要
添加s
标志,以便(.+)
也与换行符匹配。
preg_match('/required info(.+)info'.'./is', $str, $m);
print_r($m);