正则表达式替换 - 匹配并清空所有不包含特定字符的行



我不能使用 grep。事实上,我在记事本2中。当我想删除包含字符"c"的行时,我正在使用替换对话框 (Ctrl+H):

Search string: ".*c.*"
Replace with: "" (nothing)

之后,我对行进行排序,并删除空行。

但是现在我需要清空所有实际上不包含字符"c"的行。是否可以在记事本2中执行此操作?

如果我可以在Notepad2中做到这一点,那么我也可以使用JavaScript的字符串替换来做到这一点,我想。

是的,您可以锚定模式并使用否定字符类。

Find: ^[^c]*$

解释:

^          # the beginning of the string
 [^c]*     # any character except: 'c' (0 or more times)
$          # before an optional n, and the end of the string

最新更新