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

时间:2021-12-17 21:39:04

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. anyone knows how could i do this in notepad++? thanks.

我想为一个项目排序一个巨大的列表,我需要从包含4个以上单词的长列表中删除所有行。谁知道我怎么能在记事本++中这样做?谢谢。

2 个解决方案

#1


2  

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. See a demo on regex101.com.
Thanks to @SebastianProske for spotting an error in the original expression.

您需要启用多线模式。请参阅regex101.com上的演示。感谢@SebastianProske发现原始表达式中的错误。

#2


0  

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

This works in TextWrangler; It might work in notepad++.

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

#1


2  

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. See a demo on regex101.com.
Thanks to @SebastianProske for spotting an error in the original expression.

您需要启用多线模式。请参阅regex101.com上的演示。感谢@SebastianProske发现原始表达式中的错误。

#2


0  

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

This works in TextWrangler; It might work in notepad++.

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