双引号的正则表达式不在 start/end 行或 preceding/following 逗号

Regex for double quotes not at start/end of line or preceding/following a comma

示例数据为:

"3610212505","3610212505","Jack is 6'2" tall"

我想用 PHP 中的正则表达式模式转义出现在 6'2" 中的 2 之后的双引号。此行是我正在尝试的更大 CSV 文件的一部分净化。

基本上任何双引号都不是:

类似

/"(?!(,|$|\w))/
  • (?!(,|$|\w)) 确保 " 后面没有 ,$ 字符串结尾或 \w

Regex Demo

例子

preg_replace("/\"(?!(,|$|\w))/", "", "\"3610212505\",\"3610212505\",\"Jack is 6'2\" tall\"");
=> "3610212505","3610212505","Jack is 6'2 tall"
(?<!^)(?<!,)"(?!$|,)

尝试 this.See 演示。

https://regex101.com/r/wZ0iA3/9

$re = "/(?<!^)(?<!,)\"(?!$|,)/im";
$str = "\"3610212505\",\"3610212505\",\"Jack is 6'2\" tall\"";
$subst = "";

$result = preg_replace($re, $subst, $str);