Php preg_match获取部分文本

Php preg_match获取部分文本,php,regex,preg-match,Php,Regex,Preg Match,我有这段文字…… ==================================================== 澳大利亚医学会主席史蒂夫·汉布尔顿周一表示,任何改变都会阻止人们去看医生 “我认为我们必须确定我们试图解决的问题是什么,”哈姆布尔顿博士说 周日,联邦卫生部长彼得·达顿(Peter Dutton)拒绝终止关于该提案得到政府支持的猜测,只是表示他致力于确保卫生系统“可持续并可供未来使用” 达顿在一份声明中表示:“我们不会对有关审计委员会可能建议或不建议的猜测发表评论。” 该报

我有这段文字……

====================================================

澳大利亚医学会主席史蒂夫·汉布尔顿周一表示,任何改变都会阻止人们去看医生

“我认为我们必须确定我们试图解决的问题是什么,”哈姆布尔顿博士说

周日,联邦卫生部长彼得·达顿(Peter Dutton)拒绝终止关于该提案得到政府支持的猜测,只是表示他致力于确保卫生系统“可持续并可供未来使用”

达顿在一份声明中表示:“我们不会对有关审计委员会可能建议或不建议的猜测发表评论。”

该报告预测,如果实行共同支付,“全科医生服务”的数量每年将下降3%,从而从2014年7月开始减缓医疗保险福利计划支出的增长

================================================

我想匹配上面段落中的所有引号,

预期结果:

  • “我认为我们必须确定我们正在努力解决的问题是什么,”汉布尔顿博士说
  • 达顿在一份声明中表示:“我们不会对有关审计委员会可能建议或不建议的猜测发表评论。”
  • 我正在使用此代码,但不工作

    $match = array();
    
    preg_match_all("/\'\'(.*)\'\'/i", $str, $match);
    

    如果可以使用正则表达式,我将使用它,但问题是如何获取引号,这将提供“预期结果”下的内容。但是请注意,它与您提供的文本中的所有引号不匹配,例如“可持续和可访问未来”。我知道您的预期结果中没有这些,我只是澄清它们被忽略了,这就是我的解决方案没有提供它们的原因

    $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
    

    $text=下面是一个工作代码示例:

    $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);
    
    正则表达式的解释:

    • (?:[^.?!\s][^.?!“]+)?
      允许句子以非引号材料开头。以非空格、非标点字符开头,然后匹配非标点、非引号字符
    • “[^”]*”
      一个引号、非引号字符和另一个引号
    • [^.?!”]*
      可选,更多非引号、非标点符号字符
    • [.?!]”?
      最后一个标点符号和最后一个引号(可选)

    已知问题:它不会匹配包含多个引号或引号开始前的句点的句子。例如:
    布朗先生说,“我想,”然后继续说,“所以我是。”

    编辑:这解决了上述问题:

    preg_match_all('/(?=[^.?!\s])(?:(?:(?:Mrs?|Dr|Rev)\.\s|[^.?!"])*?"[^"]*?[^.?!]")+(?:(?:(?:Mrs?|Dr|Rev)\.\s|[^.?!"])*?(?:"[^"]*?[.?!]"?|[.?!]))/i', $str, $match);
    
    它匹配上面的每一句话,并为这句话生成一个匹配项:

    布朗先生说:“我想,”接着格林先生坐立不安地说,“所以我是。” 演示:


    所有用表示动词的引号:

    \B"[^"]+"(?=.+?said)[^.]+.
    

    您应该将其与多行和大小写Insensive(可选)标志一起使用:


    对不起,上面代码中的颜色格式。这是因为我使用了
    (?=[^.?!\s])(?:(?:(?:Mrs?|Dr|Rev)\.\s|[^.?!"])*?"[^"]*?[^.?!]")+(?:(?:(?:Mrs?|Dr|Rev)\.\s|[^.?!"])*?(?:"[^"]*?[.?!]"?|[.?!]))
    
    \B"[^"]+"(?=.+?said)[^.]+.
    
    preg_match_all('/\B"[^"]+"(?=.+?said)[^.]+./mi', $text, $matches);