Search code examples
regexmatchnotepad++line

Regex to delete lines with a certain amount of dots?


I want to delete lines with 3 or more dots. I tried to delete it myself but it deletes all lines with dots while I need only lines containing 3 or more.

For example

p..z.e.4c.e.u.j abc1
aaaaaa 11111
ju.as.h.e.s 125.60.000.
p.iv.p.f.j abcde
r.g.9c 11111112
o.u.n.ggz 12..345.6
ffffffff 22222
1.2.3.45 abcddd
ddddddddddd 33333333

to this result

aaaaaa 11111
r.g.9c 11111112
ffffffff 22222
ddddddddddd 33333333

Solution

    • Ctrl+H
    • Find what: ^.*(?:\..*?){3}.*(?:\R|\Z)
    • Replace with: LEAVE EMPTY
    • CHECK Wrap around
    • CHECK Regular expression
    • UNCHECK . matches newline
    • Replace all

    Explanation:

    ^               # beginning of line
      .*            # 0 or more any character but newline
      (?:           # non capture group
        \.          # a dot
        .*?         # 0 or more any character but newline, not greedy
      ){3}          # end group, must appear 3 times
      .*            # 0 or more any character but newline
    (?:\R|\Z)       # non capture group, any kind of linebreak OR end of file
    

    Screen capture (before):

    enter image description here

    Screen capture (after):

    enter image description here