Regular Expressions (regex) are somewhat of a mystery for many developers. We admit that they are something that we use often enough to warrant a deeper understanding of how they work. On the flip side, there are so many tried and tested regex patterns on the Internet that just reusing one that already exists is most times easier than trying to create one yourself. The subject of regex is much larger than what can be explained in a single chapter in this book.
Therefore, in this chapter, we will merely introduce some of the concepts of regex. For a deeper understanding of regex, further study is needed. For the purpose of this book, however, we will take a closer look at how regex are created and how they can be applied to some common programming problems. In this chapter, we will cover the following recipes:
Getting started with regex
Matching a valid date
Sanitizing input
Dynamic regex matching