The article's lead section may need to be rewritten. The reason given is: definition and lead are only about regular expression metacharacters, but article is not. (April 2019) |
A metacharacter is a character that has a special meaning to a computer program, such as a shell interpreter or a regular expression (regex) engine.
In POSIX extended regular expressions, there are 14 metacharacters that must be escaped (preceded by a backslash (\
)) in order to drop their special meaning and be treated literally inside an expression: opening and closing square brackets ([
and ]
); backslash (\
); caret (^
); dollar sign ($
); period/full stop/dot (.
); vertical bar/pipe symbol (|
); question mark (?
); asterisk (*
); plus and minus signs (+
and -
); opening and closing curly brackets/braces ({
and }
); and opening and closing parentheses ((
and )
).
For example, to match the arithmetic expression (1+1)*3=6
with a regex, the correct regex is \(1\+1\)\*3=6
; otherwise, the parentheses, plus sign, and asterisk will have special meanings.