fbpx
Wikipedia

Metacharacter

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.

Other examples edit

Some other characters may have special meaning in some environments.

Escaping edit

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.[2]

See also edit

References edit

  1. ^ "Character entity references in HTML 4". www.w3.org. W3C. December 24, 1999. Retrieved 2018-11-19.
  2. ^ a b c "Command shell overview". docs.microsoft.com. Microsoft. September 10, 2009. Retrieved 2018-11-19.
  3. ^ "The Open Group Base Specifications Issue 7: fprintf". pubs.opengroup.org. The Open Group. 2018. Retrieved 2018-11-19.
  4. ^ a b "LIKE (Transact-SQL)". docs.microsoft.com. Microsoft. March 14, 2017. Retrieved 2018-11-19.

metacharacter, article, lead, section, need, rewritten, reason, given, definition, lead, only, about, regular, expression, metacharacters, article, please, help, improve, lead, read, lead, layout, guide, april, 2019, learn, when, remove, this, template, messag. 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 Please help improve the lead and read the lead layout guide April 2019 Learn how and when to remove this template message 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 Contents 1 Other examples 2 Escaping 3 See also 4 ReferencesOther examples editSome other characters may have special meaning in some environments In some Unix shells the semicolon is a statement separator In XML and HTML the ampersand amp introduces an HTML entity 1 It also has special meaning in MS DOS Windows Command Prompt 2 In some Unix shells and MS DOS Windows Command Prompt the less than sign and greater than sign lt and gt are used for redirection and the backtick grave accent is used for command substitution 2 In many programming languages strings are delimited using quotes or In some cases escape characters and other methods are used to avoid delimiter collision e g He said Hello In printf format strings the percent sign is used to introduce format specifiers and must be escaped as to be interpreted literally 3 In SQL the percent is used as a wildcard character 4 In SQL the underscore is used to match any single character 4 Escaping editMain 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 2 See also editMarkup languageReferences edit Character entity references in HTML 4 www w3 org W3C December 24 1999 Retrieved 2018 11 19 a b c Command shell overview docs microsoft com Microsoft September 10 2009 Retrieved 2018 11 19 The Open Group Base Specifications Issue 7 fprintf pubs opengroup org The Open Group 2018 Retrieved 2018 11 19 a b LIKE Transact SQL docs microsoft com Microsoft March 14 2017 Retrieved 2018 11 19 nbsp This programming language related article is a stub You can help Wikipedia by expanding it vte Retrieved from https en wikipedia org w index php title Metacharacter amp oldid 1155057584, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.