我如何为每个列出的项目添加引号,逗号,返回,3个空格,然后重复

时间:2019-07-10 23:10:54

标签: notepad++

我有一长串看起来像这样的物品:

item 1
item 2
item 3
item 2700

我需要它看起来像这样:

   "item 1",
   "item 2",
   "item 3",
   "item 2700"

1 个答案:

答案 0 :(得分:2)

  • Ctrl + H
  • 查找内容:^.+$(\z)?
  • 替换为:"$0"(?1:,)
  • 检查环绕
  • 检查正则表达式
  • 取消检查. matches newline
  • 全部替换

说明:

^           # beginning of line
  .+        # 1 or more any character but newline
$           # end of line
(\z)?       # optional group 1, end of file

替换:

            # 3 spaces
"$0"        # the whole match (i.e. one line), surrounded with quotes
(?1:,)      # conditional replacement, 
                if group 1 exists (i.e. end of file)
                    do nothing
                else
                    add a comma

给定示例的结果

   "item 1",
   "item 2",
   "item 3",
   "item 2700"    

屏幕截图:

enter image description here