如何删除超过 x 个单词的行?在记事本++正则表达式中

How to remove lines with more than x words? in notepad++ regex

我想为一个项目排序一个巨大的列表,我需要从包含超过 4 个单词的长列表中删除所有行。 任何人都知道我怎么能在记事本++中做到这一点? 谢谢。

你可以想出一些办法。喜欢:

^(?:\b\w+[^\w\r\n]*){4,}$
# ^   - anchor the expression to the beginning of a line
# (?: - a non capturing group
# \b  - a word boundary
# \w+ - match word characters greedily
# [^\w\r\n] - do not match any of these character (classes) 
# the construct {4,} repeats this pattern 4 or more times
# $   - match the end of the line

您需要开启 multiline 模式。参见 a demo on regex101.com
感谢@SebastianProske 发现原始表达式中的错误。

\n?^(\S+[^\S\n]+){3,}\S+.*$

这适用于 TextWrangler;它可能适用于记事本++。