Common Basic Regular Expression (BRE) metacharacters include the following:
-
.(Dot): Matches any single character except a newline.- Example:
a.bmatchesacb,a1b, etc.
- Example:
-
^(Caret): Matches the beginning of a line.- Example:
^abcmatchesabcat the start of a line.
- Example:
-
$(Dollar Sign): Matches the end of a line.- Example:
xyz$matchesxyzat the end of a line.
- Example:
-
*(Asterisk): Matches zero or more occurrences of the preceding character or group.- Example:
a*matches ``,a,aa, etc.
- Example:
-
?(Question Mark): Matches zero or one occurrence of the preceding character or group. (Note: In BRE, this must be escaped as\?to be treated as a metacharacter.)- Example:
a\?bmatchesborab.
- Example:
-
[ ](Square Brackets): Matches any single character within the brackets.- Example:
[abc]matchesa,b, orc.
- Example:
-
[^ ](Negated Square Brackets): Matches any single character not within the brackets.- Example:
[^abc]matches any character excepta,b, orc.
- Example:
-
{}(Curly Braces): Specifies a specific number of occurrences of the preceding character or group. (Note: In BRE, this must be escaped as\{and\}.)- Example:
a\{2\}matchesaa.
- Example:
-
( )(Parentheses): Groups patterns together. (Note: In BRE, this must be escaped as\(and\).)- Example:
\(abc\)matches the exact stringabc.
- Example:
-
|(Pipe): Represents alternation (logical OR). (Note: In BRE, this must be escaped as\|.)- Example:
abc\|defmatches eitherabcordef.
- Example:
Summary
These metacharacters allow for flexible pattern matching in BRE, but remember that some of them require escaping to function as intended.
