简体   繁体   English

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

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

I want to sort a huge list for a project, and I need to delete all the lines from long lists that contain more than 4 words. 我想为一个项目排序一个巨大的列表,我需要删除长列表中包含4个以上单词的所有行。 anyone knows how could i do this in notepad++? 有谁知道我怎么能在记事本++? thanks. 谢谢。

You could come up with sth. 你可能想出某事。 like: 喜欢:

^(?:\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

You need to have the multiline mode on. 您需要启用multiline模式。 See a demo on regex101.com . 参见regex101.com上的演示
Thanks to @SebastianProske for spotting an error in the original expression. 感谢@SebastianProske发现原始表达式中的错误。

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

This works in TextWrangler; 这在TextWrangler中有效; It might work in notepad++. 它可能在notepad ++中工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM