Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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_Preg Replace - Fatal编程技术网

Php 忽略字符双重外观的正则表达式模式

Php 忽略字符双重外观的正则表达式模式,php,regex,preg-replace,Php,Regex,Preg Replace,寻找一个正则表达式模式,该模式检测单个字符(特定),但在出现双字符或三字符时忽略它。。。N abcde <- looking for this (c's separated by another character) abccdce <- not this (immediately repeating c's) 提示:我知道如何做相反的事情-替换双精度,但忽略单精度 $pattern = '/c\1{1}/x'; $replacement = 'FOO'; preg_replace

寻找一个正则表达式模式,该模式检测单个字符(特定),但在出现双字符或三字符时忽略它。。。N

abcde <- looking for this (c's separated by another character)
abccdce <- not this (immediately repeating c's)
提示:我知道如何做相反的事情-替换双精度,但忽略单精度

$pattern = '/c\1{1}/x';
$replacement = 'FOO';
preg_replace($pattern, $replacement, $text);
您可以为此使用:

(?<!c)c(?!c)
代码:

(?<!c)  # negative lookbehind to fail the match if previous position as c
c       # match literal c
(?!c)   # negative lookahead to fail the match if next position as c
$repl = preg_replace('/(?<!c)c(?!c)/', 'FOO', $text);
$repl=preg_replace('/(?为什么“abccdce”不产生“abccdFOOe”?)作为regex模式中的旁注
{1}
总是没有用的。
$repl = preg_replace('/(?<!c)c(?!c)/', 'FOO', $text);