© Russ Ferguson and Keith Cirkel 2017

Russ Ferguson and Keith Cirkel, JavaScript Recipes, 10.1007/978-1-4302-6107-0_20

20. Working with Regular Expressions

Russ Ferguson and Keith Cirkel2

(1)Ocean, New Jersey, USA

(2)London, UK

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 literalsvar 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); ...

Get JavaScript Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.