You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用正则表达式在Notepad++中为每行添加闭合括号?

Add Closing Parentheses to SQL Lines in Notepad++ with Regex

Absolutely! This is a straightforward task with Notepad++'s regular expression find-and-replace tool. Here's how to do it quickly and safely:

Step-by-Step Instructions

  1. Open your file in Notepad++, then press Ctrl+H to launch the Find and Replace dialog.
  2. In the Search Mode section at the bottom left, select Regular expression (make sure the ". matches newline" option is unchecked—this is the default setting).
  3. Enter this pattern in the Find what field:
    ^(insert into agent_sales values\(.+)
    
  4. Enter this in the Replace with field:
    \1)
    
  5. Click Replace All, and all your lines will instantly get the closing parenthesis added.

How This Works

Let's break down the regex to make it clear:

  • ^ anchors the match to the start of each line, ensuring we only target lines that begin with your SQL insert statement.
  • (insert into agent_sales values\(.+) is a capture group: it grabs the entire line from the start of the insert command up to the end of the trailing number (.+ matches any characters until the line ends, excluding the newline).
  • \1 in the replacement field refers to the content we captured, and we just append a ) to close the parentheses properly.

Alternative (More Specific Matching)

If you know every line strictly follows the (number, number) pattern, you can use a tighter regex to avoid accidental matches on other lines:

  • Find what: ^(insert into agent_sales values\(\d+,\d+)
  • Replace with: \1)

Either method will give you the desired cleaned-up SQL:

insert into agent_sales values(61,39858)
insert into agent_sales values(101,5786)
insert into agent_sales values(40,32230)
insert into agent_sales values(122,39873)
insert into agent_sales values(183,40588)
insert into agent_sales values(141,47961)

内容的提问来源于stack exchange,提问作者tonyibm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:29:40