Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在我的正则表达式中排除引号中的字符串?_Php_Regex - Fatal编程技术网

Php 如何在我的正则表达式中排除引号中的字符串?

Php 如何在我的正则表达式中排除引号中的字符串?,php,regex,Php,Regex,我想把除了字符串以外的所有东西都用引号括起来,有没有一种简单的方法 正则表达式如下:\b([\w]+)\b |(“([^”])*” 下面是包含引号的示例: PHP有一个很好的功能,名为*SKIP/*FAIL(名为回溯控制动词,正如@Federico正确指出的那样): 请参阅。 在PHP中,这将是: $regex = '~"[^"]+"(*SKIP)(*FAIL)|\b(\w+)\b~'; $string = 'this one "but this one not" but again this

我想把除了字符串以外的所有东西都用引号括起来,有没有一种简单的方法

正则表达式如下:
\b([\w]+)\b |(“([^”])*”

下面是包含引号的示例:


PHP
有一个很好的功能,名为
*SKIP/*FAIL
(名为回溯控制动词,正如@Federico正确指出的那样):

请参阅。

PHP
中,这将是:

$regex = '~"[^"]+"(*SKIP)(*FAIL)|\b(\w+)\b~';
$string = 'this one "but this one not" but again this one';
preg_match_all($regex, $string, $matches);
print_r($matches);
我的熟食版本:

"[^"]*"\s*\K(\w+)|(\w+)

根据您前面的问题判断,它们被命名为回溯控制动词,我想您需要。请参阅。
"[^"]*"\s*\K(\w+)|(\w+)