regex - POSIX.2 regular expressions
A (modern) RE is one(!) or more nonempty(!) branches, separated by ’|‘. It matches anything that matches one of the branches.
A branch is one(!) or more pieces, concatenated. It matches a match for the first, followed by a match for the second, and so on.
A piece is an atom possibly followed by a single(!) '', ’+’, ’?’, or bound. An atom followed by '' matches a sequence of 0 or more matches of the atom. An atom followed by ’+’ matches a sequence of 1 or more matches of the atom. An atom followed by ’?’ matches a sequence of 0 or 1 matches of the atom.
An atom is a regular expression enclosed in ”()” (matching a match for the regular expression), an empty set of ”()” (matching the null string)(!), a bracket expression (see below), ’.’ (matching any single character), ’^’ (matching the null string at the beginning of a line), ’$’ (matching the null string at the end of a line)
A bracket expression is a list of characters enclosed in ”[]“. It normally matches any single character from the list (but see below). If the list begins with ’^’, it matches any single character (but see below) not from the rest of the list. If two characters in the list are separated by ’-’, this is shorthand for the full range of characters between those two (inclusive) in the collating sequence, for example, “[0-9]” in ASCII matches any decimal digit.