Preg_match 匹配开始和结束之间的单词
Preg_match match words between start and end
我讨厌 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);
这显示了太多的单词,因为我有 "start point" 并且没有模式结束。但我不知道,如何创建带有这样的结尾分隔符的 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"
请帮我创建模式。
你可以试试这个,
$regex = "/s\(\\"(.*?)\\"\);/s";
并从输出
中替换+
和"
我讨厌 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);
这显示了太多的单词,因为我有 "start point" 并且没有模式结束。但我不知道,如何创建带有这样的结尾分隔符的 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"
请帮我创建模式。
你可以试试这个,
$regex = "/s\(\\"(.*?)\\"\);/s";
并从输出
中替换+
和"