Special Characters in Basic Regular Expressions

Special characters in POSIX Basic Regular Expressions (BREs) have special properties when within certain contexts.

They become ordinary characters (matching themselves) when outside of these contexts, or when escaped with a preceding \.

Special Characters

CharacterSpecial Property
.matches any single character
[denotes the start of a bracket expression
\escapes the following special character into an ordinary character
*matches the preceding single character/subexpression/back-reference 0+ consecutive times
^limits an entire BRE to match from the beginning of a string
$limits an entire BRE to match to the end of the string

Contexts

Character(s)Are Special when...
. [ \outside of bracket expressions
*outside of bracket expressions, and not first in a BRE/subexpression
^first in a BRE (a left anchor)
$last in a BRE (a right anchor)

Notes:


The Open Group Base Specifications Issue 7 (9. Regular Expressions), GNU sed regular expression extensions