Skip to main content
Regexflux
Lesson 1 of 120 completed

Introduction to Regular Expressions

Learn what regex patterns are and how literal characters match text exactly.· 5 min

Concept

A regular expression (regex) is a sequence of characters that defines a search pattern. You can use regex to find, validate, and manipulate text in any programming language.

The simplest regex patterns match literal characters exactly. The pattern hello matches the text "hello" wherever it appears in a string — no special syntax required.

Most characters in a regex pattern match themselves: letters, digits, and many punctuation marks are all literal. You'll learn about the exceptions (special characters) in the next lesson.

/cat/g

Matches the literal text "cat" anywhere in a string

I have a cat
the cat sat on the mat
concatenate
I have a dog
/hello world/g

Matches the exact phrase including the space

say hello world now
hello world!
hello world
world hello

Exercise

Write a pattern that matches the word "regex" (case-sensitive, lowercase only).

Your pattern:

Must match

I love regex
regex is powerful
learn regex today
regex101 is a tool

Must not match

REGEX is cool
Regex tools
pattern matching
regular expressions