Reputation: 33
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
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+)? *$
To match all the lines which has atmost three words.
^ *\S+ *(\S+ *(?:\S+)?)? *$
Upvotes: 2