如何在记事本++中删除带有方括号和这些方括号中的所有其他方括号的单词?

时间:2020-02-22 04:04:36

标签: notepad++

有办法吗?我要

"windows": [
            { "x": 2, "y": 0 }
        ]

以一无所有而告终。如果括号中也有更多坐标,我希望同样发生。

2 个答案:

答案 0 :(得分:0)

Ctrl + H 查找内容:(?:^ |(?<=]))[^] [] *?(?= [| $) 替换为:留空 检查环绕 检查正则表达式 全部替换

说明:

(?:#启动非捕获组 ^#行首 | # 要么 (?<=])#正向后看,零长度断言that
确保之前有一个方括号 )#个结束组 [^] [] *? #否定字符类,任何 没有打开或关闭方括号,可能出现0次或多次,不是贪婪

(?=#开始正向超前,零长度断言 确保我们拥有 [#一个开放的方括号 | # 要么 $#行尾 )#ed lookahead

给定示例的结果:

[A B C] [D E F] [G H I] [J K L] M N O] [P Q R [S T U]

答案 1 :(得分:0)

  • Ctrl + H
  • 查找内容:^\h*"windows":\h*\[\s+{.+?}\s+\]\s+
  • 替换为:LEAVE EMPTY
  • 检查 匹配案例
  • 检查 环绕
  • 检查 正则表达式
  • 全部替换

说明:

^               # beginning of line
  \h*           # 0 or more horizontal spaces
  "windows":    # literally
  \h*           # 0 or more horizontal spaces
  \[            # opening square bracket
  \s+           # 1 or more any spaces, including linebreak
  {             # opening brace
  .+?           # 1 or more any character, not greedy
  }             # closing brace
  \s+           # 1 or more any spaces, including linebreak
  \]            # closing square bracket
  \s+           # 1 or more any spaces, including linebreak

屏幕截图(之前):

enter image description here

屏幕截图(之后):

enter image description here