Product Code Database
Example Keywords: machine -apple $16
barcode-scavenger
   » » Wiki: Metacharacter
Tag Wiki 'Metacharacter'.
Tag

Metacharacter
 (

 C O N T E N T S 

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 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.


Other examples
Some other characters may have special meaning in some environments.
  • In some the (";") is a statement separator.
  • In and , the ("&") introduces an HTML entity. It also has special meaning in /Windows Command Prompt.
  • In some Unix shells and MS-DOS/Windows Command Prompt, the and greater-than sign ("<" and ">") are used for redirection and the /grave accent ("`") is used for command substitution.
  • In many programming languages, strings are using (" or '). In some cases, (and other methods) are used to avoid delimiter collision, e.g. "He said, \"Hello\"".
  • In printf format strings, the ("%") is used to introduce format specifiers and must be escaped as "%%" to be interpreted literally. In , the percent is used as a wildcard character.
  • In SQL, the ("_") is used to match any single character.


Escaping
The term "to escape a metacharacter" means to make the metacharacter ineffective (to strip it of its special meaning), causing it to have its literal meaning. For example, in , a dot (".") stands for any single character. The regular expression "A.C" will match "ABC", "A3C", or even "A C". However, if the "." is escaped, it will lose its meaning as a metacharacter and will be interpreted literally as ".", causing the regular expression "A\.C" to only match the string "A.C".

The usual way to escape a character in a regex and elsewhere is by prefixing it with a backslash ("\"). Other environments may employ different methods, like MS-DOS/Windows Command Prompt, where a caret ("^") is used instead.


See also

Page 1 of 1
1
Page 1 of 1
1

Account

Social:
Pages:  ..   .. 
Items:  .. 

Navigation

General: Atom Feed Atom Feed  .. 
Help:  ..   .. 
Category:  ..   .. 
Media:  ..   .. 
Posts:  ..   ..   .. 

Statistics

Page:  .. 
Summary:  .. 
1 Tags
10/10 Page Rank
5 Page Refs