{ }
DevToolsLabs
Back to Guides

Regex Explained for Beginners: A Friendly Guide to Regular Expressions

Regular Expressions (Regex) can look like a cat walked across a keyboard, but they are incredibly logical once you learn the alphabet. In this guide, we'll break down the most common symbols so you can start writing your own patterns.

March 10, 2026
8 min Read

What is Regex?

A Regular Expression is a sequence of characters that forms a search pattern. When you search for data in a text, you can use this search pattern to describe what you are looking for.

Think of it as "Find and Replace" on steroids. Instead of searching for a literal word like "apple", you can search for "any word that ends in 'ple' and starts with a vowel".

The Basics: Literals and Meta-characters

The simplest regex is just a literal string. If you search for hello, it will match exactly the text "hello".

The power comes from meta-characters. These are characters with special meanings:

  • . (Dot): Matches any single character except newline.
  • ^ (Caret): Matches the start of a string.
  • $ (Dollar): Matches the end of a string.
  • * (Asterisk): Matches 0 or more occurrences of the preceding character.
  • + (Plus): Matches 1 or more occurrences of the preceding character.

Character Classes: The [ ] Brackets

Brackets allow you to match a specific set of characters. For example, [aeiou] will match any single vowel.

You can also use ranges:

  • [a-z]: Any lowercase letter.
  • [A-Z]: Any uppercase letter.
  • [0-9]: Any digit.

Quantifiers: How Many?

Quantifiers tell Regex how many times a character should appear:

  • ?: 0 or 1 time (optional).
  • {n}: Exactly n times.
  • {n,}: n or more times.
  • {n,m}: Between n and m times.
\d{3}-\d{3}-\d{4}  // Matches a US phone number like 123-456-7890

Common Shorthands

Developers use these daily to save time:

  • \\d: Any digit (same as [0-9]).
  • \\w: Any "word character" (letters, numbers, and underscore).
  • \\s: Any whitespace (spaces, tabs).
  • \\D: Any NON-digit.

The Common Flags

Flags change how the whole pattern behaves:

  • g (Global): Don't stop at the first match; find all of them.
  • i (Case Insensitive): Ignore whether letters are uppercase or lowercase.
  • m (Multiline): Treat start and end characters (^ and $) as working on every line, not just the whole string.

Summary

Regex is a language of its own. It takes practice to read, but once you master these basic building blocks, you'll be able to perform complex data validation and extraction that would take dozens of lines of standard code.