Go to the first, previous, next, last section, table of contents.

How do I search for, delete, or replace unprintable (8-bit or control)

 characters?

To search for a single character that appears in the buffer as, for example, `\237', you can type "C-s C-q 2 3 7". (This assumes the value of search-quote-char is 17 (ie., C-q).) Searching for ALL unprintable characters is best done with a "regexp" search. The easiest regexp to use for the unprintable chars is the complement of the regexp for the printable chars.

Regexp for the printable chars: [\t\n\r\f -~]

Regexp for the unprintable chars: [^\t\n\r\f -~]

To type some of these special characters in an interactive argument to isearch-forward-regexp or re-search-forward, you need to use C-q. (`\t', `\n', `\r', and `\f' stand respectively for TAB, LFD, RET, and C-l.) So, to search for unprintable characters using re-search-forward:

  M-x re-search-forward RET [^ TAB C-q LFD C-q RET C-q C-l SPC -~] RET

Using isearch-forward-regexp:

  M-C-s [^ TAB RET C-q RET C-q C-l SPC -~]

To delete all unprintable characters, simply use a replace-regexp:

  M-x replace-regexp RET [^ TAB C-q LFD C-q RET C-q C-l SPC -~] RET RET

Replacing is similar to the above. {I need to write the text for this part of the answer!}

Notes:

Here are the Emacs Lisp forms of the above regexps:

  ;; regexp matching all printable characters:
  "[\t\n\r\f -~]"
  ;; regexp matching all unprintable characters:
  "[^\t\n\r\f -~]"

Go to the first, previous, next, last section, table of contents.