Preg_match匹配开始和结束之间的单词

时间:2015-03-21 09:13:33

标签: php preg-match

我讨厌preg_match语法!

[file.txt的] 来源:

  sth = s("Would you like to go to the cinema "+
                               "With me?");
        }
        else if (something)
        {
            sth = s("Would you like to go to the cinema "+
                               "With me?");
        } else {
sth = s("Sure, no problem");
}

PHP:

$file = file_get_contents("file.txt");
$file = str_replace(PHP_EOL, '', $file);
preg_match_all("/s\(\"(.*) /", $file, $matches);
var_dump($matches);

这显示了太多的单词,因为我有"起点"没有结束的模式。但我不知道,我怎么能用这样的结尾分隔符创建preg:

preg_match("/ [s(" .... ")] /")

我想从源头抽奖:

"Would you like to go to the cinema With me?" 
"Would you like to go to the cinema With me?" 
"Sure, no problem"

请帮我创建模式。

1 个答案:

答案 0 :(得分:1)

你可以试试这个,

$regex = "/s\\(\\\"(.*?)\\\"\\);/s";

并从输出中替换+"

Demo