HeoLab
ToolsBlogAboutContact
HeoLab

Free developer tools with AI enhancement. Built for developers who ship.

Tools

  • JSON Formatter
  • JWT Decoder
  • Base64 Encoder
  • Timestamp Converter
  • Regex Tester
  • All Tools →

Resources

  • Blog
  • What is JSON?
  • JWT Deep Dive
  • Base64 Explained

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 HeoLab. All rights reserved.

Tools work in your browser. Zero data retention.

HomeBlogRegular Expressions 101: A Beginner's Complete Guide
Table of Contents▾
  • Table of Contents
  • What is a Regular Expression?
  • Literal Characters
  • Character Classes
  • Anchors
  • Quantifiers
  • Groups and Alternation
  • Flags
tutorials#regex#regular-expressions#tutorial

Regular Expressions 101: A Beginner's Complete Guide

Learn regular expressions from scratch — syntax, anchors, character classes, quantifiers, and groups with practical examples.

Trong Ngo
February 22, 2026
2 min read

Table of Contents

  • What is a Regular Expression?
  • Literal Characters
  • Character Classes
  • Anchors
  • Quantifiers
  • Groups and Alternation
  • Flags

What is a Regular Expression?

A regular expression (regex) is a pattern that describes a set of strings. It's used to search, validate, and transform text.

const pattern = /hello/;
pattern.test("hello world"); // true
pattern.test("goodbye");     // false

Literal Characters

The simplest regex matches literal text: /cat/ matches the string 'cat' anywhere in the input.

Special characters that need escaping: . * + ? ^ $ { } [ ] | ( ) \

Character Classes

[abc]      - matches a, b, or c
[a-z]      - any lowercase letter
[0-9]      - any digit
[^abc]     - NOT a, b, or c
\d         - digit [0-9]
\w         - word character [a-zA-Z0-9_]
\s         - whitespace
.          - any character (except newline)

Anchors

^     - start of string
$     - end of string
\b    - word boundary
/^hello/.test('hello world') // true
/world$/.test('hello world') // true
/\bcat\b/.test('cats')       // false — not a whole word

Quantifiers

*      - 0 or more
+      - 1 or more
?      - 0 or 1 (optional)
{n}    - exactly n times
{n,m}  - between n and m times

Groups and Alternation

/(cat|dog)/  // matches 'cat' or 'dog'

const match = '2025-02-22'.match(/(\d{4})-(\d{2})-(\d{2})/);
match[1] // '2025'
match[2] // '02'

Flags

i  - case-insensitive
g  - global (find all matches)
m  - multiline (^ and $ match line boundaries)

Practice with the Regex Tester — with real-time match highlighting.

Try These Tools

Regex Tester & Debugger

Test regular expressions against strings in real-time. Visualize matches, groups, and flags.

Related Articles

Mastering Regex Lookahead and Lookbehind

2 min read

How to Write Efficient Regular Expressions

2 min read

Using Regex for Form Validation: Patterns and Pitfalls

2 min read

Back to Blog

Table of Contents

  • Table of Contents
  • What is a Regular Expression?
  • Literal Characters
  • Character Classes
  • Anchors
  • Quantifiers
  • Groups and Alternation
  • Flags

Related Articles

Mastering Regex Lookahead and Lookbehind

2 min read

How to Write Efficient Regular Expressions

2 min read

Using Regex for Form Validation: Patterns and Pitfalls

2 min read