我可以在这个我用来测试的网站上勾选"global“。我取消了global,并尝试将/g添加到我的正则表达式中,但它不起作用。我尝试手动添加它,因为在实时环境中,正则表达式引擎没有全局过滤器。
我已经尝试了/g和正则表达式的开始和结束,并关闭了自动过滤器
(?=(Booked|Cancelled|Reschedule))(?<status>\1)|(?<acct>M\d{9})|(?
=Procedure Date:\s*(?<m>\d{2})\/(?<d>\d{2})\/(?<y>\d{2}))如果我从网站中删除修饰符或尝试自己添加它,它会忽略matches.here is a de o
发布于 2019-04-30 00:02:32
我不太清楚你在问什么,但是在PHP中你可以使用preg_match_all。它甚至可以处理换行符,因此您不必将它们替换为{newline}。
假设regex已完成:
<?php
$file = $argv[1];
$rgx="/(?=(Booked|Cancelled|Reschedule))(?<status>\1)|(?<acct>M\d{9})|(?=Procedure Date:\s*(?<m>\d{2})\/(?<d>\d{2})\/(?<y>\d{2}))/";
$fp = fopen($file, "r");
$data = fread($fp, filesize($file));
fclose($fp);
preg_match_all($rgx, $data, $array);
var_dump($array);我已经将代码另存为test.php,并按如下方式进行了验证。
$ php test.php txt_newline.txt > test.a
$ php test.php txt_no_newline.txt > test.b
$ md5sum test.a test.b
5880b9977830066f5b8bd0bea41ebb0f test.a
5880b9977830066f5b8bd0bea41ebb0f test.b我希望它能帮上忙。Here's preg_match_all的完整手册。
https://stackoverflow.com/questions/55876946
复制相似问题