1. Tech

Your suggestion is on its way!

An email with a link to:


was emailed to:

Thanks for sharing About.com with others!

Regular Expressions

6. Meta Characters

clr gif

The ^, $, and \ characters that we looked at in the last tutorial have a special meaning in the regular expression syntax. Such characters are commonly known as meta characters. There are a number of other meta characters with regard to regular expressions and while we wont be looking at what some of these are used for until later tutorials we need to know what these meta characters are in order to make sure that we escape them when we use them in regular expressions where we want the characters to have their normal meaning.

Here is a list of all of the meta characters.

^ $ \ / ( ) | ? + * [ ] { } , .

We have already looked at the first two of these and how you escape them to give them back their normal meaning. The other characters in this list need to be escaped the same way if you want to use them as the characters themselves without their special meanings.

var regexp = /\\|\//;

If I now tell you that | has the special meaning of or then using what you already know the meaning of this regular expression should be obvious. The or operator in a regular expression means that the text must match either what preceeds the | or it must match what immediately follows. Since the preceding \ and following / are both escaped (by preceding them with \) they have their regular meanings instead of their special meanings (of ecsape character and regular expression delimiter respectively). This regular expression will therefore match with either a slash or slosh (backslash) character.

©2016 About.com. All rights reserved.