我有这个文字....
=============================================== =====
澳大利亚医学会主席史蒂夫汉布尔顿周一表示任何会阻止人们去看医生的改变。
“我认为我们必须确定我们试图解决的问题是什么,”汉布尔顿博士说。周日,联邦卫生部长彼得·达顿拒绝结束有关该提案得到政府支持的猜测,只是说他致力于确保卫生系统“可持续,未来可及”。
“我们不会就审计委员会可能会或不会建议的内容进行评论,”Dutton先生在一份声明中表示。该报告预测,如果实行共同支付,“GP服务”的数量将每年下降3%,从而减缓2014年7月医疗保险福利计划支出的增长。
=============================================== =
我想匹配上一段中的所有引号,
预期结果:
我正在使用此代码,但无法正常工作..
$match = array();
preg_match_all("/\'\'(.*)\'\'/i", $str, $match);
如果可以使用正则表达式我将使用它,但问题是我如何抓住行情
答案 0 :(得分:1)
使用声明动词:
声明的所有引号\B"[^"]+"(?=.+?said)[^.]+.
你应该使用它与多线和& case insensetive(可选)标志:
preg_match_all('/\B"[^"]+"(?=.+?said)[^.]+./mi', $text, $matches);
答案 1 :(得分:0)
这将提供您在“预期结果”下的内容。但请注意,它与您提供的文本中的所有引号不匹配,例如“可持续且可访问未来”。我知道你在预期的结果中没有这些,我只是澄清它们被省略了,这就是我的解决方案没有提供它们的原因。
$text = <<<EOD
====================================================
Australian Medical Association president Steve Hambleton said on Monday any change which would deter people from seeing a doctor.
"I think we've got to identify what the problem is that we're trying to solve," Dr Hambleton said.
On Sunday federal Health Minister Peter Dutton refused to end speculation that the proposal had the government's support, only saying he was committed to ensuring the health system was "sustainable and accessible to the future".
"We won't be commenting on speculation around what the Commission of Audit may or may not recommend," Mr Dutton said in a statement.
The report predicts that the volume of "GP services" would decline by 3 per cent a year if co-payment was introduced, slowing the growth in Medicare Benefits Schedule outlays from July 2014.
================================================
EOD;
$matches = null;
preg_match_all('#"[ a-zA-Z,\']+"[ a-zA-Z,\']+\.#m', $text, $matches);
var_dump($matches); // $matches[0] contains array of all matched quotes
&GT;
答案 2 :(得分:0)
以下是工作代码的示例:
$str = <<<EOT
Australian Medical Association president Steve Hambleton said on Monday any change which would deter people from seeing a doctor.
"I think we've got to identify what the problem is that we're trying to solve," Dr Hambleton said.
On Sunday federal Health Minister Peter Dutton refused to end speculation that the proposal had the government's support, only saying he was committed to ensuring the health system was "sustainable and accessible to the future".
"We won't be commenting on speculation around what the Commission of Audit may or may not recommend," Mr Dutton said in a statement.
The report predicts that the volume of "GP services" would decline by 3 per cent a year if co-payment was introduced, slowing the growth in Medicare Benefits Schedule outlays from July 2014.
EOT;
$match = array();
preg_match_all('/(?:[^.?!\s][^.?!"]+)?"[^"]*"[^.?!"]*[.?!]"?/i', $str, $match);
var_dump($match);
这会产生:
array(1) {
[0]=>
array(4) {
[0]=>
string(98) ""I think we've got to identify what the problem is that we're trying to solve," Dr Hambleton said."
[1]=>
string(228) "On Sunday federal Health Minister Peter Dutton refused to end speculation that the proposal had the government's support, only saying he was committed to ensuring the health system was "sustainable and accessible to the future"."
[2]=>
string(132) ""We won't be commenting on speculation around what the Commission of Audit may or may not recommend," Mr Dutton said in a statement."
[3]=>
string(190) "The report predicts that the volume of "GP services" would decline by 3 per cent a year if co-payment was introduced, slowing the growth in Medicare Benefits Schedule outlays from July 2014."
}
}
正则表达式的解释:
(?:[^.?!\s][^.?!"]+)?
允许句子以非引用材料开头。以非空格,非标点字符开头,然后匹配非标点符号,非引号字符。"[^"]*"
引用,非引号字符和另一个引用。[^.?!"]*
(可选)更多非引号,非标点字符。[.?!]"?
最终的标点符号,以及可选的最终引号。
已知问题:在报价开头之前,它不会与多个报价或句号相匹配。例如,这:Mr. Brown said, "I think," then continued, "therefore I am."
编辑:这解决了以上问题:
preg_match_all('/(?=[^.?!\s])(?:(?:(?:Mrs?|Dr|Rev)\.\s|[^.?!"])*?"[^"]*?[^.?!]")+(?:(?:(?:Mrs?|Dr|Rev)\.\s|[^.?!"])*?(?:"[^"]*?[.?!]"?|[.?!]))/i', $str, $match);
它匹配上述每个句子,并为这句话产生匹配:
先生。布朗说,“我想,”然后格林先生坐立不安,“因此我就是这样。”
演示:
(?=[^.?!\s])(?:(?:(?:Mrs?|Dr|Rev)\.\s|[^.?!"])*?"[^"]*?[^.?!]")+(?:(?:(?:Mrs?|Dr|Rev)\.\s|[^.?!"])*?(?:"[^"]*?[.?!]"?|[.?!]))