在引用的元素中查找逗號我試圖用CSV的雙引號元素中的佔位符文本替換逗號。正則表達式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,」
我試圖通過讓我的lookbehind匹配僅針對一個dbl引用,並且周圍沒有dble引號或組三個DBL引號,但是碰上了「向後看組沒有明顯的最大長度」的錯誤,
使用csv解析器解析,修改和重新創建csv會不會更容易? – assylias