About Regular Expressions
A regular expression, also known as a regex or regexp, is a way of defining a search pattern. Think of regexes as wildcards on steroids. Using wildcards, *.txt matches any-thing followed by the string ".txt". But regular expressions let you e.g.: match specific characters, refer back to previ-ous matches in the expression, include conditionals within the expression, and much more.
This Refcard assumes basic familiarity with program structures, but no prior knowledge of regular expressions. It would be wise to play with as many of the examples as possible, since mastering regex requires a good deal of practical experience.
The Structure of a Regular Expression
All regular expressions follow the same basic structure: expression plus flag. In the following example, "regexp?" is the expression, and "mg" is the flag used.
new RegExp("regexp?", "mg"); // returns /regexp?/mg