Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.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_Delimiter - Fatal编程技术网

Php 用于替换两个分隔符之间出现的所有字符的正则表达式

Php 用于替换两个分隔符之间出现的所有字符的正则表达式,php,regex,delimiter,Php,Regex,Delimiter,我在这里需要一些RegEx神的帮助,因为我已经试了两个小时了,但我无法理解这一点: 样本来源: DisplayText="cf font="Arial" size="10" complexscriptsfont="Arial" complexscriptssize="10" asiantextfont="Arial" fontcolor="595959""> 我想将“with”的所有实例替换为“”,但前提是这些实例位于封闭的内部”。即

我在这里需要一些RegEx神的帮助,因为我已经试了两个小时了,但我无法理解这一点:

样本来源:

DisplayText="cf font="Arial" size="10" complexscriptsfont="Arial" complexscriptssize="10" asiantextfont="Arial" fontcolor="595959"">
我想将“with
的所有实例替换为“”,但前提是这些实例位于封闭的内部”。即,上述实例应变为:

DisplayText="cf font="Arial" size="10" complexscriptsfont="Arial" complexscriptssize="10" asiantextfont="Arial" fontcolor="595959"">
DisplayText中文本的确切结构是未知的,并且一直都在变化,但不管是什么情况,我们都不希望“在外部”。正如您所看到的,外部“保持不变”。这只应出现在以DisplayText=“开始,以”>结束的字符串中

因此,查找需要编辑的字符串很容易:

/DisplayText\="(.*?)"\>/
现在我们只需要在1美元内将“替换为

这是针对PHP的

非常感谢您的帮助

这个代码怎么样:

这个代码怎么样:


最终,这起作用了

$postproc = preg_replace('#(DisplayText="|\G(?!\A))([^">]*)"(?!\s*>)#', '$1$2"', $postproc);
所以我只需要添加DisplayText,以防止正则表达式变得过于热心,并开始接触XML中的其他标记


谢谢大家,尤其是revo的建议,我似乎无法支持revo的评论?

最后这一切都成功了

$postproc = preg_replace('#(DisplayText="|\G(?!\A))([^">]*)"(?!\s*>)#', '$1$2"', $postproc);
所以我只需要添加DisplayText,以防止正则表达式变得过于热心,并开始接触XML中的其他标记


感谢大家,尤其是revo的建议,我似乎无法对revo的评论进行投票?

不幸的是,使用htmlentities将无法工作,因为该字符串嵌入到一个更大的XML文件中,我们不想转换任何实体。我们唯一的选择是preg_replace。你不能提取字符串,运行函数,然后替换字符串?不,那不是那么容易。您需要
/DisplayText=“[^>]*?”>/
。也可以尝试
preg\u replace(''.'(=“|\G(?!\A))([^“>]*)“(?!\s*>)#'、'$1$2;quote'、$str)
。请看这里的实时演示!但是,这(至少preg\u replace,而不是实时演示)也会转换只有外部的字符串,而没有任何
变成
,不幸的是,使用HTMLenties无法工作,因为这个字符串嵌入在一个更大的XML文件中,所以我们不想转换任何实体。我们唯一的选择是preg_replace。你不能提取字符串,运行函数,然后替换字符串?不,那不是那么容易。您需要
/DisplayText=“[^>]*?”>/
。还可以尝试
preg_replace('.'(=“|\G(?!\A))([^”>]*)“(?!\s*>)#'、'$1$2;quote'、$str)
。请看这里的实时演示!不过,这(至少是preg_replace,而不是实时演示)也会转换只有外部“而没有任何
”的字符串:
变成