Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Metacharacter
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{short description|Character that has a special meaning to a computer program}} {{Lead rewrite|reason=definition and lead are only about regular expression metacharacters, but article is not |date=April 2019}} A '''metacharacter''' is a [[Character (computing)|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 (<code>\</code>) β in order to drop their special meaning and be treated literally inside an expression: opening and closing square brackets (<code>[</code> and <code>]</code>); backslash (<code>\</code>); caret (<code>^</code>); dollar sign (<code>$</code>); period/full stop/dot (<code>.</code>); vertical bar/pipe symbol (<code>|</code>); question mark (<code>?</code>); asterisk (<code>*</code>); plus and minus signs (<code>+</code> and <code>-</code>); opening and closing curly brackets/braces (<code>{</code> and <code>}</code>); and opening and closing parentheses (<code>(</code> and <code>)</code>). For example, to match the arithmetic expression <code>(1+1)*3=6</code> with a regex, the correct regex is <code>\(1\+1\)\*3=6</code>; otherwise, the parentheses, plus sign, and asterisk will have special meanings. ==Other examples== {{Anchor|Examples}} Some other characters may have special meaning in some environments. * In some [[Unix shell]]s the [[semicolon]] (";") is a [[Comparison of programming languages (syntax)#Statements|statement separator]]. * In [[XML]] and [[HTML]], the [[ampersand]] ("&") introduces an [[Character encodings in HTML|HTML entity]].<ref name="W3Ccer">{{cite web |title=Character entity references in HTML 4 |url=https://www.w3.org/TR/html4/sgml/entities |website=www.w3.org |publisher=[[W3C]] |access-date=2018-11-19 |language=en |date=December 24, 1999}}</ref> It also has special meaning in [[MS-DOS]]/[[cmd.exe|Windows Command Prompt]].<ref name="MSFTcso">{{cite web |title=Command shell overview |url=https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490954(v=technet.10) |website=docs.microsoft.com |publisher=[[Microsoft]] |access-date=2018-11-19 |language=en-us |date=September 10, 2009}}</ref> * In some Unix shells and MS-DOS/Windows Command Prompt, the [[less-than sign]] and [[greater-than sign]] ("<" and ">") are used for [[redirection (computing)|redirection]] and the [[backtick]]/grave accent ("`") is used for [[command substitution]].<ref name="MSFTcso" /> * In many [[programming language]]s, [[String (computer science)|string]]s are [[Delimiter|delimited]] using [[Quotation mark|quotes]] (" or '). In some cases, [[escape character]]s (and other methods) are used to avoid [[delimiter collision]], e.g. "He said, \"Hello\"". * In [[printf format string]]s, the [[percent sign]] ("%") is used to introduce format specifiers and must be escaped as "%%" to be interpreted literally.<ref name="TOGfprintf">{{cite web |title=The Open Group Base Specifications Issue 7: fprintf |url=http://pubs.opengroup.org/onlinepubs/9699919799/functions/printf.html |website=pubs.opengroup.org |publisher=[[The Open Group]] |access-date=2018-11-19 |date=2018}}</ref> In [[SQL]], the percent is used as a [[wildcard character]].<ref name="TSQL-LIKE" /> * In SQL, the [[underscore]] ("_") is used to match any single character.<ref name="TSQL-LIKE">{{cite web |title=LIKE (Transact-SQL) |url=https://docs.microsoft.com/en-us/sql/t-sql/language-elements/like-transact-sql?view=sql-server-2017 |website=docs.microsoft.com |publisher=[[Microsoft]] |access-date=2018-11-19 |language=en-us |date=March 14, 2017}}</ref> ==Escaping== {{Main article|Escape character}} 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 [[PCRE]], 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.<ref name="MSFTcso" /> ==See also== * [[Markup language]] ==References== {{Reflist}} [[Category:Formal languages]] [[Category:Pattern matching]] [[Category:Programming language topics]] {{Prog-lang-stub}}
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Anchor
(
edit
)
Template:Cite web
(
edit
)
Template:Lead rewrite
(
edit
)
Template:Main article
(
edit
)
Template:Prog-lang-stub
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Search
Search
Editing
Metacharacter
Add topic