Search code examples
regexnotepad++

Remove lines containing numbers and/or symbols in notepad++


I would like to remove all lines which contains numbers and/or symbols, for ex:

1
00:00:00,000 --> 00:00:04,080
random text 1

2
00:00:04,080 --> 00:00:04,920
random text 2

3
00:00:07,480 --> 00:00:08,800
random text 3

I did try with ^\s*([0-9 00*]+\s*)+$ using regex but it only removes lines 1, 5 and 9. resulting with

00:00:00,000 --> 00:00:04,080
random text1

00:00:04,080 --> 00:00:04,920
random text2

00:00:07,480 --> 00:00:08,800
random text3

and it should be

random text 1

random text 2

random text 3

can this be done in notepad++? thanks in advance


Solution

  • Assuming you want to completely remove entire lines containing only an integer number or 2 time values, you may try using this pattern:

    Find:   ^(?:\d+|\d{2}(?::\d{2}){2},\d{3} --> \d{2}(?::\d{2}){2},\d{3})$\R
    Replace: (empty)
    

    Demo

    This pattern will match:

    • ^(?: from the start of the line match either
      • \d+ a positive integer
      • | OR
      • \d{2}(?::\d{2}){2},\d{3} --> \d{2}(?::\d{2}){2},\d{3} 2 time values
    • )$ end of the line
    • \R also match ending newline (either \n or \r\n)