Brooks
Brooks

Reputation: 119

notepad++ regex to clean .txt of lines with less than X characters or only spaces

I'm using this ^.{0,10}(\r\n?|\n|$) to clean my .txt files from lines with less than 10 characters and it works great so far.

The problem I have is that the SPACE is counted as a character and I have lines containing only spaces or lots of spaces and few other characters and I want to remove those lines too.
Please help me with the correct regex to achieve that.

Upvotes: 0

Views: 193

Answers (2)

CollinD
CollinD

Reputation: 7573

If I'm understanding this properly, you want to count all whitespace as zero characters? This should work

^([\S]?[\s]*){0,10}(\r\n?|\n|$)

This will match any lines with 10 or fewer characters that are NOT whitespace

Upvotes: 1

acdcjunior
acdcjunior

Reputation: 135792

How about "trimming" the line? That is, accepting (or ignoring, whatever you call it) spaces (\s*) before or after the string.

^\s*.{0,10}\s*(\r\n?|\n|$)
 ^^^       ^^^
  '---------'---- added these \s*

See regex 101 demo here.

Upvotes: 2

Related Questions