sna*_*ahl 2 regex replace notepad++
我有一个包含大约600条记录的CSV文件,我需要用[空格]替换一些[CRLF],但只有当[CRLF]位于两个["](引号)之间时才有.当第二个["]时遇到然后它应该跳过该行的其余部分并转到文本中的下一行.
我真的没有一个起点.希望有人提出建议.
例:
John und Carol,,Smith,,,J.S.,,,,,,,,,,,,,+11 22 333 4444,,,,,"streetx 21[CRLF]
New York City[CRLF]
USA",streetx 21,,,,New York City,,,USA,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Normal,,My Contacts,[CRLF]
Run Code Online (Sandbox Code Playgroud)
在这种情况下,第一个["]之后的两个[CRLF]需要用空格[]替换.当遇到第二个["]时,跳过该行的末尾并转到下一行.
然后再次,现在在下一行,遇到第一个["]之后替换所有[CRLF]直到遇到第二个["].[CRLF]的数量不尽相同.在CSV文件中,逗号[,]之前(23)和之后(65)的2个引号["]的数量是不变的.
所以也许可以使用逗号计数器.我不知道.
感谢您的反馈.
这将只使用一个正则表达式(在Notepad ++中测试):
在Find what字段中输入此正则表达式:
((?:^|\r\n)[^"]*+"[^\r\n"]*+)\r\n([^"]*+")
在Replace with字段中输入此字符串:
$1 $2
确保Wrap around选中复选框(和Regular expression单选按钮).
Replace All根据需要执行多次(直到弹出"0次更换"对话框).
说明:
(
(?:^|\r\n) Begin at start of file or before the CRLF before the start of a record
[^"]*+ Consume all chars up to the opening "
" Consume the opening "
[^\r\n"]*+ Consume all chars up to either the first CRLF or the closing "
) Save as capturing group 1 (= everything in record before the target CRLF)
\r\n Consume the target CRLF without capturing it
(
[^"]*+ Consume all chars up to the closing "
" Consume the closing "
) Save as capturing group 2 (= the rest of the string after the target CRLF)
Run Code Online (Sandbox Code Playgroud)
注意:*+是占有量词.适当使用它们以加快执行速度.
更新:
这个更正式的正则表达式版本适用于任何换行符序列(\r\n,\r或\n):
((?:^|[\r\n]+)[^"]*+"[^\r\n"]*+)[\r\n]+([^"]*+")
| 归档时间: |
|
| 查看次数: |
10043 次 |
| 最近记录: |