uizhc
uizhc

Reputation: 33

Delete lines which contains less than 3 words

I need to Delete lines which contains less than 3 words:

I tried such regex ^.+\s.+\s.+$ but it selects all lines:

Upvotes: 1

Views: 691

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174786

The below regex would match all the lines which has less than 3 words ie, upto two words.

^ *\S+\s(?:\S+)? *$

OR

^ *\S+ *(?:\S+)? *$

DEMO

To match all the lines which has atmost three words.

^ *\S+ *(\S+ *(?:\S+)?)? *$

DEMO

Upvotes: 2

Related Questions