Regular Expressions For Regular Folk

Introduction

Regular expressions (“regexes”) allow defining a pattern and executing it against strings. Substrings which match the pattern are termed “matches”.

A regular expression is a sequence of characters that define a search pattern.

Regex finds utility in:

  • input validation
  • find-replace operations
  • advanced string manipulation
  • file search or rename
  • allow lists and deny lists

Simultaneously, regular expressions are ill-suited for other kinds of problems:

  • parsing XML or HTML
  • exactly matching dates

There are several regex implementations—regex engines—each with its own quirks and features. This book will avoid going into the differences between these, instead sticking to features that are, for the most part, common across engines.

The example blocks throughout the book use JavaScript under the hood. As a result, the book may be slightly biased towards JavaScript’s regex engine.