4

Is it possible to remove every line in a notepad++ Not Containing

a   b   c   d   e   f   g   h   i   j   k   l   m
n   o   p   q   r   s   t   u   v   w   x   y   z

A   B   C   D   E   F   G   H   I   J   K   L   M
N   O   P   Q   R   S   T   U   V   W   X   Y   Z

,   .   '

Like that :

enter image description here

Remove Non-ascii

.*[^\x00-\x7F]+.*

Remove Numbers

.*[0-9]+.*

Text :

example
example'
example,
example.


example123
éxample è
[example/+
example'/é,
example,*
exa'mple--
example@
example"
moon93
  • 129
  • 3
  • 11
  • http://stackoverflow.com/questions/8264391/notepad-inverse-regex-replace-all-but-string – Harsha W May 17 '17 at 10:02
  • @WiktorStribiżew , I want to remove all lines containing letters+numbers , I want just **letters** + **, ' .** in lines – moon93 May 17 '17 at 10:10

3 Answers3

3

You may use

^(?![a-zA-Z,.']+$).+$\R?

The regex matches any non-empty line (.+) that does not only consist of ASCII letters, ,, . or '. \R? at the end matches an optional line break.

Details:

  • ^ - start of a string
  • (?![a-zA-Z,.']+$) - a negative lookahead that fails the match if its pattern is not matched: [a-zA-Z,.']+ - 1 or more ASCII letters, comma, period or single quote up to the end of the line ($)
  • .+ - 1+ chars other than line break char
  • $ - end of a line
  • \R? - an optional line break char (sequence)

enter image description here

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
2

You can remove them like this:

Find what: ^.*[^a-zA-Z.,'].*$
Replace with: ``

Explanation:

  • .* for any text
  • the negated character class [^...] for any unwanted character
  • then again .* for more any text
  • You need to wrap it into ^...$ to match the whole line

If you want to delete the linefeed characters, then you can use \r?\n instead of the $ sign. I.e.: ^.*[^a-zA-Z.,'].*\r?\n

Tamas Rev
  • 7,008
  • 5
  • 32
  • 49
  • Thanks Sir , for helping me ^^ – moon93 May 17 '17 at 10:15
  • In Notepad++, negated character classes match line breaks (unlike in Vim). Also, if you add `\r?\n` at the end, the last line at the end of the document that matches the criteria won't be removed. – Wiktor Stribiżew May 17 '17 at 10:15
  • So, then `^.*[^a-zA-Z.,'].*$\R?` must be better because the `$` after the negated character class prevents matching line breaks. Then the optional `\R` should make sure it can delete the last line too. – Tamas Rev May 17 '17 at 10:26
1

Try to replace all this match

^.+?[^a-zA-Z,.'\r\n]+(.|\r?\n)
Fei Xia
  • 21
  • 5