grep: Fundamental Structure
3.1 Fundamental Structure
=========================
The fundamental building blocks are the regular expressions that match a
single character. Most characters, including all letters and digits,
are regular expressions that match themselves. Any meta-character with
special meaning may be quoted by preceding it with a backslash.
A regular expression may be followed by one of several repetition
operators:
‘.’
The period ‘.’ matches any single character.
‘?’
The preceding item is optional and will be matched at most once.
‘*’
The preceding item will be matched zero or more times.
‘+’
The preceding item will be matched one or more times.
‘{N}’
The preceding item is matched exactly N times.
‘{N,}’
The preceding item is matched N or more times.
‘{,M}’
The preceding item is matched at most M times. This is a GNU
extension.
‘{N,M}’
The preceding item is matched at least N times, but not more than M
times.
The empty regular expression matches the empty string. Two regular
expressions may be concatenated; the resulting regular expression
matches any string formed by concatenating two substrings that
respectively match the concatenated expressions.
Two regular expressions may be joined by the infix operator ‘|’; the
resulting regular expression matches any string matching either
alternate expression.
Repetition takes precedence over concatenation, which in turn takes
precedence over alternation. A whole expression may be enclosed in
parentheses to override these precedence rules and form a subexpression.
An unmatched ‘)’ matches just itself.