Metacharacter

From Wikipedia, the free encyclopedia
Jump to: navigation, search

A metacharacter is a character that has a special meaning (instead of a literal meaning) to a computer program, such as a shell interpreter or a regular expression engine.

In regular expressions, there are 12 metacharacters that must always be preceded by a backslash, \, to be used inside of the expression:

The opening square bracket [, the closing square bracket ], the backslash \, the caret ^, the dollar sign $, the period or dot ., the vertical bar or pipe symbol |, the question mark ?, the asterisk or star *, the plus sign +, the opening round bracket ( and the closing round bracket ).[1]

If you want to use any of these characters as a literal in a regex, you need to escape them with a backslash. If you want to match 1+1=2, the correct regex is 1\+1=2. Otherwise, the plus sign will have a special meaning.

Examples[edit]

See also[edit]

References[edit]