1

In Emacs, when using M-x replace-regexp, how can one specify matching a tab which is not at the beginning of a line? I know how to match a tab which is at the beginning of a line by using ^, but don't know how to do the opposite.

3

When searching you can do: C-u C-s . TAB IOW the regular expression uses . instead of ^.

The regexp pattern . matches "any character" with the notable exception of the line separator character (aka LF), so .a is a regexp that matches an a preceded by a character that's not a line-separator, hence an a that's not at the beginning of a line.

  • 1
    Thanks. Could you explain what the key means? – Tim Jan 16 '18 at 20:25
  • Can . in .a match any character including a? So can match aa at the beginning of a line? – Tim Jan 17 '18 at 2:57
  • 1
    @Tim: Yes, indeed. If you want to skip all lines that start with a, then you need something like ^[^a\n]+a. – Stefan Jan 17 '18 at 13:15
  • Does emacs' regex support \n? – Tim Jan 17 '18 at 13:24
  • @Tim: Emacs's regexps accept the LF character like any other character, yes. When typing a regexp at the minibuffer you can insert an LF character with C-j, when typing a regexp in Elisp code (i.e. inside a string) you can use \n to insert an LF character into the regexp. – Stefan Jan 17 '18 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.