Next: posix-extended regular expression syntax, Previous: posix-basic regular expression syntax, Up: Regular Expressions
The character ‘.’ matches any single character except newline.
Bracket expressions are used to match ranges of characters. Bracket expressions where the range is backward, for example ‘[z-a]’, are ignored. Within square brackets, ‘\’ is taken literally. Character classes are supported; for example ‘[[:digit:]]’ will match a single decimal digit. Non-matching lists ‘[^...]’ do not ever match newline.
GNU extensions are supported:
Grouping is performed with parentheses ‘()’. A backslash followed by a digit acts as a back-reference and matches the same thing as the previous grouped expression indicated by that number. For example ‘\2’ matches the second group expression. The order of group expressions is determined by the position of their opening parenthesis ‘(’.
The alternation operator is ‘|’.
The characters ‘^’ and ‘$’ always represent the beginning and end of a string respectively, except within square brackets. Within brackets, ‘^’ can be used to invert the membership of the character class being specified.
The characters ‘*’, ‘+’ and ‘?’ are special anywhere in a regular expression.
Intervals are specified by ‘{’ and ‘}’. Invalid intervals are treated as literals, for example ‘a{1’ is treated as ‘a\{1’
The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.