Notepad ++:删除除数字和连字符模式以外的所有内容

时间:2019-12-12 14:12:00

标签: windows replace find pattern-matching notepad++

Notepad ++:我有一个包含电话号码的文件,所有文件的类型均为123-123-1234 我需要匹配模式any3digitsDASHany3digitsDASHany4digits,并删除任何与此模式不匹配的内容

我有

  XL/XXL  1 
 349 "
" 
242 8 . . 
. 22140 
  089-247-3065

 XL/XXL  1 
 349 "
"  
206/1 .6 . .
. 30000
 092-273-6125

我想

089-247-3065

092-273-6125

在此先感谢您的帮助!

3 个答案:

答案 0 :(得分:2)

  • Ctrl + H
  • 查找内容:\G.*?(?<!\d)(\d{3}-\d{3}-\d{4}(?!\d)|\z)
  • 替换为:$1\n
  • 检查 环绕
  • 检查 正则表达式
  • 检查 . matches newline
  • 全部替换

说明:

\G                  # restart from last match position
.*?                 # 0 or more any character
(?<!\d)             # negative lookbehind, make sure we haven't digit before
(                   # start group 1
  \d{3}-\d{3}-\d{4} # the string you're searching for
  (?!\d)            # negative lookahead, make sure we haven't digit after
 |                # OR
  \z                # end of file
)                   # end of group

屏幕截图(之前):

enter image description here

屏幕截图(之后):

enter image description here

答案 1 :(得分:1)

grep -o '\b[[:digit:]]\{3\}-[[:digit:]]\{3\}-[[:digit:]]\{4\}\b' file
089-247-3065
092-273-6125

答案 2 :(得分:1)

替换此正则表达式所找到的内容:

^.*(\d{3}[-]\d{3}[-]\d{4}).*$

并替换为

\1
在Notepad ++中,

会隔离其行中的所有电话号码,但保留不包含电话号码的行。可以通过替换以下正则表达式将其删除:

^(?!\d{3}[-]\d{3}[-]\d{4}).*$

一无所有。

相关问题