What Is a Regular Expression?
Problem
You want to know what a regular expression is and how to use one in JavaScript.
Solution
Regular expressions are patterns used to match characters . In JavaScript, they are also objects.
The Code
Listing 20-1. Creating a Simple Regular Expression
//regular expression literals
var companyBio = 'Twitter is an online social networking service that enables users to send and read short 140-character messages called "tweets".';
var simplePattern = /(twitter)/gi;
var simplePatternConstructor = new RegExp(simplePattern); ...