How To Remove All Lines Containing Any non-ASCII Characters Using Notepad++ or Emeditor

notepadregextext editing

How do I remove all lines containing any non-ASCII keyboard characters?

I tried so many times Regular Expressions codes but none work like it should be
I even tried this code [^\x00-\x7F]+ but it didn't select all the characters

the idea come on my mind is to use this way [^a-z0-9``~!@#$%^&*()-_=+[]{}\|;:'"<>,./?] but still not work because some of this characters didn't get deselected like \ / | { } [ ] $ # ^ ( )

  1. If a line contains any characters not in the list below, I want to remove remove it or bookmark it

    0123456789`~!@#$%^&*()-_=+[]{}\/|;:'"<>,.?
    abcdefghijklmnopqrstuvwxyz
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    
  2. Simple example: There are more characters like this found here: https://en.wikipedia.org/wiki/List_of_Unicode_characters

    0123456789`~!@#$%^&*()-_=+[]{}\|;:'"<>,./?
    abcdefghijklmnopqrstuvwxyz
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    ¤©ª«¬¯°±²³´µ¶·¸¹º»¼½¾¿÷ÆIJŒœƔƕƋƕ
    ƜƝƢƸƾDžNJNjǽǾǼɁɀȾɎʒəɼʰʲʱʴʳʵʶʷʸˁˀˇˆ˟ˠ
    ˩˧Ͱͱͳʹͼͻͺ͵ͿΏΔΘΞΛΣΠΦΧΨΩΪΫάέήίΰαβδε
    θηκλμξπςρφχψωϊϋϏώϑϐϓϒϔϕϖϠϟϞϝϜϡϢ
    ϤϣϧϫϬϮϯϰϱ₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲
    ₳₴₵₶₷₸₹₺₻₼₽₾₿⅐⅑⅒⅓⅔⅕⅖⅗⅘⅙⅚⅛⅜
    ⅝⅞⅟℠℡™℣ℤ℥Ω℧ℨ℩KÅℬℭ℮ℯ⇀⇁ↀↁↂↃↄ
    ⇔⇕⇖⇗⇘⇙⇚⇛⇜⇝⇞⇟⇠⇡⇢⇣⇤⇥⇦⇧⇨⅀⅁⅂⅃⅄ⅅ
    ⅆⅇⅈⅉ⅊⅋⅌⅍ⅎ⅏ⅱⅲⅳⅴⅵⅶⅷⅸⅹⅺⅻⅼⅽ
    
  3. Expected result:

    0123456789`~!@#$%^&*()-_=+[]{}\|;:'"<>,./?
    abcdefghijklmnopqrstuvwxyz
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    

Best Answer

[^\x00-\x7F] works fine, but, if you want to use a long character class like [^a-z0-9``~!@#$%^&*()-_=+[]{}\|;:'"<>,./?] you have to escape characters that have a special meaning (ie. -[]\ and add linebreak \r,\n.

Your regex becomes:

 [^a-z0-9``~!@#$%^&*()\-_=+\[\]{}\\|;:'"<>,./?\r\n]
 #                    ^    ^ ^   ^            ^^^^

  • Ctrl+H
  • Find what: [^a-z0-9``~!@#$%^&*()\-_=+\[\]{}\\|;:'"<>,./?\r\n]+$ But, again, [^\x00-\x7F] works fine and is more readable
  • Replace with: LEAVE EMPTY
  • check Wrap around
  • check Regular expression
  • Replace all

Result for given example:

0123456789`~!@#$%^&*()-_=+[]{}\|;:'"<>,./?
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Related Question