WebToolsDen
Your everyday tools,in one place

2026-03-06

Regex for Beginners — How to Use Regular Expressions

What are regular expressions?

A regular expression is a pattern that describes a set of strings. Used to search text, validate input, or find-and-replace content.

The basics

Literal characters match themselves. The dot matches any single character. Caret matches start of line, dollar matches end. Square brackets create a character class matching one character from the set.

Quantifiers

Question mark: zero or one. Asterisk: zero or more. Plus: one or more. Curly braces with a number: exactly that many times. Curly braces with two numbers: between those counts.

Shorthand classes

Backslash-d: any digit. Backslash-w: any word character. Backslash-s: any whitespace. Uppercase versions match the opposite.

Useful patterns

Email (basic): word characters and symbols at domain dot extension. Date YYYY-MM-DD: four digits dash two digits dash two digits. Hexadecimal colour: hash followed by three or six hex characters.

Common mistakes

Not escaping special characters — use backslash before dot, asterisk, plus, question mark when you want the literal character. Being too greedy — use non-greedy quantifiers with a question mark suffix. Forgetting anchors — without caret and dollar, patterns match inside longer strings.

FAQ

Are regex patterns the same in all languages? Mostly yes. JavaScript, Python, and PHP all use standard PCRE-compatible regex with minor differences.

Is regex case-sensitive? By default, yes. Use the case-insensitive flag to match regardless of case.

Try the tool

All Tools →