如何使用正则表达式或 preg_match 提取引号内的文本?
How to extract text that is inside quotes with regex or preg_match?
我收到以下字符串的文本:
We have a new FB Leads "Puente Middleware".
我试图用 preg_match 提取字符串的主题,但它只是 returns 引号外而不是引号内的文本。
$getSubject = preg_match('/"([^"]*)"/', $subject);
return "We have a new FB Leads"
I want to return "Puente Middleware"
您指定了正确的捕获组,但您从未访问过替换项。试试这个版本:
$subject = "We have a new FB Leads \"Puente Middleware\"";
preg_match('/"([^"]*)"/', $subject, $results);
echo $results[1];
这会打印:
Puente Middleware
我收到以下字符串的文本:
We have a new FB Leads "Puente Middleware".
我试图用 preg_match 提取字符串的主题,但它只是 returns 引号外而不是引号内的文本。
$getSubject = preg_match('/"([^"]*)"/', $subject);
return "We have a new FB Leads"
I want to return "Puente Middleware"
您指定了正确的捕获组,但您从未访问过替换项。试试这个版本:
$subject = "We have a new FB Leads \"Puente Middleware\"";
preg_match('/"([^"]*)"/', $subject, $results);
echo $results[1];
这会打印:
Puente Middleware