在记事本++中的同一行上复制单词

问题描述

我在 Notepad++ 中有一个表名列表:

employee
manager
customer
reciepts
customer_details
employee_mapping
manager_employee_mapping

我希望在同一行中再次重复每个单词,例如:

employee employee
manager manager
customer customer

等等。我想这样做是为了制作一个 sql 脚本,我必须在其中选择表名作为字符串和表的总数。喜欢:

select 'employee',count(1) from employee    union
select 'manager',count(1) from manager     union

同样适用于所有行。 现在,可以使用 ctrl+F 或在开头和结尾插入轻松插入 select/union/count/,/from 之类的词。但是将表名作为字符串获取是很棘手的。

有没有办法在Notepad ++中做到这一点而无需手动执行此操作? 这个列表只是一个示例,我有一个包含 100 多个表的列表。请帮忙。

解决方法

  • Ctrl+H
  • 查找内容:^\w+$
  • 替换为:select '$0',count\(1\) from $0 union
  • 检查 环绕
  • 检查 正则表达式
  • 全部替换

说明:

^           # beginning of line
\w+         # 1 or more word character [a-zA-Z0-9_],this will be kept in group 0
$           # end of line

屏幕截图(之前):

enter image description here

屏幕截图(之后):

enter image description here