-1

So i got this:

123456asdsa
444444dfsdsdg
3443fsdfdsd
77gdsggfgf

and i only wish to delete any lines that contain 6 digits no matter word count so it can be like this:

3443fsdfdsd
77gdsggfgf

the only thing i found out is this regexp [0-9]{6} which makes me select only the 6 digits but with no words so what should i do? thank you

3 Answers3

0

You can use

^(?=\w*\d{6})\S+\s

Lookahead in that line for 6 digits, then replace that line and the following newline with the empty string:

https://regex101.com/r/mz0vMY/2

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
  • This regex will delete lines will select lines with more than 6 digits and that should not be the case – Onyambu Jul 24 '18 at 02:37
0

you could use:

^\D*\d{6}(?!\d).* #or ^\D*\d{6}(?=\D).*

In this case, you will see whether there is any non-digits before the digits. When you get six digits, ensure the next is a non-digit. ie only select lines with 6 digits. Those with 7 digits or more or those with less than 6 digits are not selected:

regex Demo

Onyambu
  • 67,392
  • 3
  • 24
  • 53
0

Your requirement is not very clear so I am giving you several alternatives, which I hope one of them fits your need.

If you want to select lines containing 6 consecutive digits and no other digits, you can use

^\D*\d{6}\D*$

^                      start of line
 \D*                   some optional non-digit, 
    \d{6}              followed by 6 digits, 
         \D*           followed by some optional non-digit 
            $          till end of line

If you want to select lines containing 6 digits (not necessary to be consecutive), you can use this

^(\D*\d){6}\D*$


^                       start of line
 (\D*\d)                group of optional non-digit then 1 digit
        {6}             above group happening for 6 times 
                            (i.e. 6 digits in total)
           \D*$         follow by non-digits till end of line

If you want to select lines containing a sequence of exactly 6 digits, you can

^.*(\b|\D)\d{6}(\b|\D).*$

^.*                              start of line, followed by some chars
   (\b|\D)                       followed word boundary or non-digit
          \d{6}                  6 digits
               (\b|\D)           followed word boundary or non-digit
                      .*$        followed by some chars till end of line

Update:

With info from @WiktorStribiżew, Notepad++ may be handling \D in unexpected way as it may match newlines. You can simply replace the \D in above regex to [^0-9\n\r] for preferred behavior.

Adrian Shum
  • 38,812
  • 10
  • 83
  • 131
  • just a note, for better performance, you could replace the use of group `( ... )` with a non-capturing group `(?: ... )` – Adrian Shum Jul 24 '18 at 04:08
  • Not my downvote, but this solution is wrong because `\D` may match a line break and remove more than just 1 line with digits in it. – Wiktor Stribiżew Jul 24 '18 at 07:15
  • Oh I was not paying attention to it being for Notepad++. Well, that's strange that everyone else is using `\D \S` which is suffering from same problem though, dunno why I am the only one being downvoted :P Anyway, for a easy fix for Notepad++, simply replace `\D` with `[^0-9\n\r]` should do the work – Adrian Shum Jul 24 '18 at 08:08