Learn something new every day
More Info... by email
A metacharacter is one of a number of characters that, when used, does not represent any of the various letters or numbers that we commonly use to communicate. A metacharacter has a specific meaning such as indicating that various words should be separated in a line of code.
The metacharacter tells your computer how to proceed, in essence, explaining what to do with the characters that follow the metacharacter. In other words, a computer’s operating system will read a metacharacter, interpret what it means, and then perform an action based on that interpretation. Such an action may include instructing the system to separate statements or searching for different spellings of a word.
A metacharacter can be created from a variety of symbols, including punctuation marks. When a metacharacter is not needed, and punctuation marks are used for their original purpose, they must be set apart from the rest of the string. This can be done by either placing them within quotation marks or using a backslash. Another term for setting such a symbol apart is “escaping.”
Another example of a metacharacter is using one of the other standard symbols in a different way, such as using the the dollar sign to indicate the end of a line. A question mark is a very useful metacharacter when performing searches. You may not know precisely how a given word is spelled in a file, a common example being “honor” or “honour.”
In order to instruct your system to look for both spellings, you would type "hono(u)?r." The metcharacter, in this case the question mark, then tells your computer to find the word honor regardless of how it is spelled, with or without the “u.” On the other hand, if you’re searching for a metacharacter, you need to quote it or precede it with a backlash in order to search for it in its common usage. Say you wanted to search for just the question mark. Since it is a metacharacter, you would have to use the backslash in front of it or quotation marks around it in order to get the system to follow your command.
While some metcharacters have specific purposes or only match certain characters, there are also those that match any character. The dot, or the period, is one of them. A metacharacter that matches any character is known as a "wildcard."