在记事本++中的正则表达式以查找替换或删除部分字符串

时间:2019-05-24 16:41:14

标签: regex replace find notepad++ regex-group

这是根据引用“客户投诉”的在线数据集改编而成的。在Excel和Notepad ++中修改了数据。这种操作在字符串“ VALUES(X)”之后的每个“索引数字” [1,2,3 ...]之后直接产生了一组“额外”引号。我只想删除此“额外引号”,然后维护顺序索引号,范围从一位到五位数字,这是为使用具有135万行代码的专有数据库做的准备。


对Regex的这种笨拙的改编将“查找”一个包含引号的字符串,但是保持索引号的“替换”代码使我难以理解。任何帮助将不胜感激。

REGEX

\s\(([0-9])",|\s\(([0-9][0-9])",|\s\(([0-9][0-9][0-9])",|\s\(([0-9][0-9][0-9][0-9])",|\s\(([0-9][0-9][0-9][0-9][0-9])",

数据字符串

INSERT INTO Complaints VALUES (1","2013-07-29","consumer loan","managing the loan or lease","Wells Fargo & Company","VA","24540","phone","2013-07-30","closed with explanation","468882");

INSERT INTO Complaints VALUES (2","2013-07-29","bank account or service","using a debit or ATM card","Wells Fargo & Company","CA","95992","web","2013-07-31","closed with explanation","468889");

INSERT INTO Complaints VALUES (3","2013-07-29","bank account or service","account opening, closing, or management","Santander Bank US","NY","10065","fax","2013-07-31","closed","468879");

2 个答案:

答案 0 :(得分:1)

查找VALUES \((\d+)"-内括号将捕获数字(\d一次或多次(+),直到遇到"

然后您可以替换为VALUES \($1,其中$1是相应的捕获值。

答案 1 :(得分:1)

  • Ctrl + H
  • 查找内容:VALUES\h*\(\d+\K"
  • 替换为:LEAVE EMPTY
  • 检查环绕
  • 检查正则表达式
  • 全部替换

说明:

VALUES      # literally
\h*         # 0 or more horizontal spaces
\(          # opening parenthesis
\d+         # 1 or more digits
\K          # forget all we have seen until this position
"           # a double quote

屏幕截图:

enter image description here