Glossary

Regex

REJ-ex

A pattern for finding, matching and replacing text.

Regex (regular expression) is a pattern that describes the text you want to find. Most people say “REJ-ex,” with a soft g, though “REG-ex” is common too.

Example

const isEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
isEmail.test('hi@example.com'); // true

Common building blocks

  • \d: any digit.
  • \w: any letter, digit or underscore.
  • +: one or more of the previous item.
  • ^ and $: start and end of the text.

Why it matters

Regex is built into almost every language and editor, which makes it great for validation, search-and-replace and parsing logs. Complex patterns get hard to read fast, so keep them short and test them. For structured data like JSON or HTML, use a real parser instead.