我正在尝试用 CSV 的双引号元素中的占位符文本替换逗号。
例如,给定 CSV 中的这一行:
1,2,"three,four,five",6,7,8,"nine,ten",11,12
使用这个正则表达式(Java 的引号转义):
(?<=\")([^"]+?),([^"]+?)(?=\")
我将第一场比赛替换为:
$1<COMMA>$2
这给了我这个结果字符串:
1,2,"three<COMMA> four, five",6,7,8,"nine,ten",11,12
我对 resultString 重复这些步骤,直到不再有匹配项。以下是渐进式结果字符串:
1,2,"three<COMMA> four, five",6,7,8,"nine,ten",11,12
1,2,"three<COMMA> four<COMMA> five",6,7,8,"nine,ten",11,12
1,2,"three<COMMA> four<COMMA> five",6<COMMA>7,8,"nine,ten",11,12
1,2,"three<COMMA> four<COMMA> five",6<COMMA>7<COMMA>8,"nine,ten",11,12
1,2,"three<COMMA> four<COMMA> five",6<COMMA>7<COMMA>8,"nine<COMMA>ten",11,12
1,2,"three<COMMA> four<COMMA> five",6<COMMA>7<COMMA>8,"nine<COMMA>ten",11,12
如何调整我的正则表达式,使其仅替换列表项中的“,”而不是分隔符本身?在第三次迭代中,我得到了一个匹配:“,6,7,8”
我试图通过让我的后向匹配仅针对一个没有 dble 引号的 dbl 引用或三个 dbl 引号组成的组来防止这种情况,但遇到“后向组没有明显的最大长度”错误,