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

需求:构建特定匹配规则的正则表达式(用于Notepad++批量删行)

Solution for Your Notepad++ Regex Task

Got it, let's break down how to create the exact regex you need, and even cover the full scope of your goal (deleting all lines that don't start with whitespace followed by a number).

First: Regex for the Specific Line Format You Mentioned

If you only need to match lines that start with whitespace, followed by 1-4 non-digit characters, then at least one space, use this regex:

^\s+\D{1,4}\s+.*$

Breakdown:

  • ^ = Anchors the match to the start of the line
  • \s+ = Matches one or more whitespace characters (spaces, tabs, etc.)
  • \D{1,4} = Matches 1 to 4 non-digit characters (\D is shorthand for [^\d])
  • \s+ = Ensures there's at least one space after those non-digit characters
  • .*$ = Matches the rest of the line up to the end

Second: Regex to Delete All Non-Compliant Lines (Full Scope)

Since your end goal is to delete all lines that don't follow the "starts with whitespace + first non-whitespace is a digit" rule, this broader regex will catch every line that doesn't meet your retention criteria:

^(?!\s+\d).*$

Breakdown:

  • ^(?!...) = Negative lookahead: this tells the regex to match lines where the start does not lead into the pattern inside the lookahead
  • \s+\d = The pattern we want to KEEP (whitespace followed by a digit)
  • .*$ = Matches the entire rest of the line once the negative lookahead condition is met

How to Use in Notepad++

  • Open the Find/Replace dialog with Ctrl+H
  • Go to the Regular expression mode (uncheck ". matches newline" if you want to match individual lines; check it only if you need multi-line handling)
  • Paste the regex into the "Find what" field
  • Leave the "Replace with" field empty
  • Click "Replace All" — all unwanted lines will be deleted instantly!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:35:36