In working with regular expressions, I have been told that a dot character . will match everything.

Except for newlines \n.

Are there any other exceptions? What about the NUL character \0, or the backspace character \b, or any of the other various non-printable ASCII characters?

Do different utility/programs like sed, awk, perl, and vim behave differently or the same in this aspect?


3 Answers 3


From info regex:

3.2 The Match-any-character Operator (`.')

This operator matches any single printing or nonprinting character
except it won't match a:

      if the syntax bit `RE_DOT_NEWLINE' isn't set.

      if the syntax bit `RE_DOT_NOT_NULL' is set.
  • How come when I type info regex my manual isn't divided into chapters and sections? This section doesn't even appear.
    – Cory Klein
    Sep 21, 2011 at 18:19
  • Hmm, I don't know - I just navigated down to Common Operators and pressed Enter on "Match-any-character Operator::" Sep 21, 2011 at 18:27
  • :( I don't even have a Common Operators section. Maybe it's because of LTS Ubuntu 10.04?
    – Cory Klein
    Sep 21, 2011 at 18:29
  • @jw013 - Unfortunately, that documentation only says " '.' Matches any character, including newline."
    – Cory Klein
    Sep 21, 2011 at 18:45

. is equivalent to [^\n] for all standard UNIX regex flavours, however, on Windows it is commonly [^\r\n] due to the syntax of Windows-style line endings. On other platforms, it should evaluate to whatever the standard newline sequence is.

In Perl and some other languages, single-line mode will make . also match \n (or [\r\n] on Windows regex flavours, etc), making it literally match anything.

Bear in mind the meaning of . may change depending on the context, for example, within POSIX bracket expressions the dot character matches a literal dot.


If you use any of the Plan 9 utilities, perhaps the Sam editor, that use Structural Regular Expressions, the '.' meta-character matches every character except newline. I believe '@' matches any single character, including a newline. The nature of structural regular expressions encourages writing multi-line patters, or maybe "patterns that ignore line-structure". Looks like there's a structural regular expression Python module in Google Code, but I can't google up much else in the way of implementations.

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.