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