Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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 preg_替换不包括字符串的匹配_Php_Regex_Preg Match - Fatal编程技术网

Php preg_替换不包括字符串的匹配

Php preg_替换不包括字符串的匹配,php,regex,preg-match,Php,Regex,Preg Match,我需要将此字符串中由“{*}”包装的切片与preg_match匹配,但找不到解决方案 对我来说,匹配这样的一个中断符号很容易:'/([^”]+)/',但它对两个符号的字符串不起作用。 例如,这不起作用:'/“\{([^(\})]+)\}”/' 是否可以将所有这些由符号对包装的切片匹配到字符串中?我认为您需要在此处使用一种非reedy模式: $string = ' prepending string ... "{something wrapped with " quotes } inside of

我需要将此字符串中由“{*}”包装的切片与preg_match匹配,但找不到解决方案

对我来说,匹配这样的一个中断符号很容易:
'/([^”]+)/'
,但它对两个符号的字符串不起作用。 例如,这不起作用:
'/“\{([^(\})]+)\}”/'


是否可以将所有这些由符号对包装的切片匹配到字符串中?

我认为您需要在此处使用一种非reedy模式:

$string = ' prepending string ... "{something wrapped with " quotes } inside of braces}" appending string...';
$string .= '"{something "similar again{}}"';

我不清楚您是否需要验证
{}
是否存在于外部
“{*}”
构造中才能进行匹配。如果是,请告诉我,我将修改答案。

非常感谢,这正是我需要的。我不知道ungreedy开关。
$pattern = '/"\{(.*)\}"/U';