© Jörg Krause 2017

Jörg Krause, Introducing Regular Expressions, 10.1007/978-1-4842-2508-0_1

1. Introducing Regular Expressions

Jörg Krause

(1)Berlin, Germany

To get a head start on introducing regular expressions , I’ll start with an example. It’s one that you’ve experienced hundreds of times. When you enter customer data online, many web forms ask you for an email address. To avoid an incorrectly typed address, an immediate validation makes sense. One way would be to split the string in parts (before and after the @ character), analyzing the positions of the dots and the number of characters after the last dot (that’s the top-level domain).

After a few ifs and loops, you’re almost done. Or you simply use a regular expression:

ˆ[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)* ...

Get Introducing Regular Expressions: JavaScript and TypeScript 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.