Linux Know-How provides a collection of introductory texts on often needed Linux skills. |
Home Bash Guide for Beginners Regular expressions Regular expressions | |||||||||||||||||||||||||||||||
See also: Metacharacters, What is grep?, Pattern Matching, SED Commands | |||||||||||||||||||||||||||||||
Search the VIAS Library | Index | |||||||||||||||||||||||||||||||
Regular expressionsA regular expression is a pattern that describes a set of strings. Regular expressions are constructed analogously to arithmetic expressions by using various operators to combine smaller expressions. 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 metacharacter with special meaning may be quoted by preceding it with a backslash. Regular expression metacharactersA regular expression may be followed by one of several repetition operators (metacharacters): Table 4-1. Regular expression operators
Two regular expressions may be concatenated; the resulting regular expression matches any string formed by concatenating two substrings that respectively match the concatenated subexpressions. Two regular expressions may be joined by the infix operator "|"; the resulting regular expression matches any string matching either subexpression. Repetition takes precedence over concatenation, which in turn takes precedence over alternation. A whole subexpression may be enclosed in parentheses to override these precedence rules. Basic versus extended regular expressionsIn basic regular expressions the metacharacters "?", "+", "{", "|", "(", and ")" lose their special meaning; instead use the backslashed versions "\?", "\+", "\{", "\|", "\(", and "\)". Check in your system documentation whether commands using regular expressions support extended expressions.
|
|||||||||||||||||||||||||||||||
Home Bash Guide for Beginners Regular expressions Regular expressions |