Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I search for, delete, or replace unprintable (eight-bit or control) characters?

0
Posted

How do I search for, delete, or replace unprintable (eight-bit or control) characters?

0

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 (i.e., C-q).) Searching for all unprintable characters is best done with a regular expression (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 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 LFD C-q RET C-q C-l SPC -~] To delete all unprintable characters, simply use replace-regexp: M-x replace-regexp RET [^ TAB C-q LFD

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123