You are previewing Eloquent JavaScript.

Eloquent JavaScript

Cover of Eloquent JavaScript by Marijn Haverbeke Published by No Starch Press
O'Reilly logo

Chapter 8. Regular Expressions

At various points in the previous chapters, we had to look for patterns in string values. In Chapter 3 we extracted date values from strings by writing out the precise positions at which the numbers that were part of the date could be found. Later, in Chapter 5, we saw some particularly ugly pieces of code for finding certain types of characters in a string, for example the characters that had to be escaped in HTML output.

Regular expressions are a language for describing patterns in string data. They form a small, separate language, which is embedded inside JavaScript (as well as various other programming languages). This language is very succinct, though not very readable—big regular expressions tend to look like ...

The best content for your career. Discover unlimited learning on demand for around $1/day.