Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
    
Depending on the utility, . is either anything, or anything except newlines. –  Gilles Sep 21 '11 at 23:34

3 Answers 3

up vote 3 down vote accepted

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:

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

 null
      if the syntax bit `RE_DOT_NOT_NULL' is set.
share|improve this answer
    
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 '11 at 18:19
    
Hmm, I don't know - I just navigated down to Common Operators and pressed Enter on "Match-any-character Operator::" –  rozcietrzewiacz Sep 21 '11 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 '11 at 18:29
    
@jw013 - Unfortunately, that documentation only says " '.' Matches any character, including newline." –  Cory Klein Sep 21 '11 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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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