Lesson 1

Introducing Regular Expressions

In this lesson you’ll learn what regular expressions are and what they can do for you.

Understanding the Need

Regular expressions (often shortened as RegEx or regex) are tools, and like all tools, regular expressions are designed to solve a very specific problem. The best way to understand regular expressions and what they do is to understand the problem they solve.

Consider the following scenarios:

images You are searching for a file containing the text car (regardless of case) but do not want to also locate car in the middle of a word (for example, scar, carry, and incarcerate).

You are generating a Web page ...

Get Learning Regular Expressions, First Edition 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.