Special Symbols
When using grep -E (which enables Extended Regular Expressions), several characters are treated as special metacharacters. These include:
- . – Matches any single character (except newline).
- ^ – Matches the beginning of a line.
- $ – Matches the end of a line.
- * – Matches the preceding element zero or more times.
- + – Matches the preceding element one or more times.
- ? – Matches the preceding element zero or one time.
- { } – Specifies a repetition interval for the preceding element (e.g.,
{2,5}
). - ( ) – Groups subexpressions and captures matched text.
- | – Denotes alternation (logical OR between expressions).
- [ ] – Denotes a character class (matches any one character within the brackets).
If you need to match these symbols literally, you generally have to escape them with a backslash (e.g., \.
to match a literal period).