Regular expression syntax
The general form for defining a regular expression pattern is:
/characters/attributes
Assume that we are searching the string "THEY, the three men, left". The following are valid regular expression patterns followed by a description of what they find:
/the three/ // "the three"
/THE THREE/ig // "the three"
/th/ // "th" in "the"
/th/igm // "th" in "THEY", "the", and "three"
The slashes delimit the characters that define a regular expression. Everything between the slashes is part of a regular expression, just as everything between quotation marks is part of a string. Three letters may occur after the second slash that are not part of the regular expression. Instead, they define attributes of the regular expression. Any one, two, or three of the letters may be used, that is, any one or more of the attributes may be defined. Thus, a regular expression has three elements: literals, characters, and attributes.