RegexBuilder
← Back to the tools
🧩

Regular Expressions for Beginners: What Is a Regex and How to Read One

A regular expression (regex) is a pattern that describes a set of strings. Instead of writing ten if-statements to check a phone number, you write one pattern — and the same pattern tests, extracts and validates in any language. RegexBuilder lets you paste a pattern, test it against real text and explain every piece in plain English.

A regex is just a pattern

The pattern \d{3}-\d{4} means "three digits, a dash, four digits". Test it against 555-1234 and it matches; against 55-1234 it does not. That is the whole idea: you describe a shape, and the engine finds every string that fits it.

Literal characters are the easy part

Most letters and numbers in a pattern match themselves. In cat, the letter c matches a c, a matches an a, t matches a t. The pattern cat matches the word cat anywhere it appears.

Metacharacters do the work

A handful of characters are special: . (any character), * and + (how many), ? (optional), [] (a choice of characters), \d (any digit) and ^/$ (the edges). Everything else is literal.

Escaping: making a metacharacter literal

To match a literal dot or star, put a backslash in front: \. matches a full stop, \* matches an asterisk. Think of the backslash as "the next character is ordinary".

Read it from left to right

A regex reads like a sentence. ^\d{3}-\d{2}-\d{4}$ says "start of string, exactly three digits, a dash, exactly two digits, a dash, exactly four digits, end of string". Paste any pattern into the RegexBuilder explainer and it will read it for you, piece by piece.

Test and explain patterns free