Next: , Previous: , Up: Regular expression syntaxes   [Contents][Index]


18.7.11 ‘posix-minimal-basic’ regular expression syntax

The character ‘.’ matches any single character except the null character.

Bracket expressions are used to match ranges of characters. Bracket expressions where the range is backward, for example ‘[z-a]’, are invalid. Within square brackets, ‘\’ is taken literally. Character classes are supported; for example ‘[[:digit:]]’ will match a single decimal digit.

GNU extensions are supported:

  1. \w’ matches a character within a word
  2. \W’ matches a character which is not within a word
  3. \<’ matches the beginning of a word
  4. \>’ matches the end of a word
  5. \b’ matches a word boundary
  6. \B’ matches characters which are not a word boundary
  7. \`’ matches the beginning of the whole input
  8. \'’ matches the end of the whole input

Grouping is performed with backslashes followed by 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 character ‘^’ only represents the beginning of a string when it appears:

  1. At the beginning of a regular expression
  2. After an open-group, signified by ‘\(

The character ‘$’ only represents the end of a string when it appears:

  1. At the end of a regular expression
  2. Before a close-group, signified by ‘\)

Intervals are specified by ‘\{’ and ‘\}’. Invalid intervals such as ‘a\{1z’ are not accepted.

The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups.


Next: sed’ regular expression syntax, Previous: posix-extended’ regular expression syntax, Up: Regular expression syntaxes   [Contents][Index]