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/gMatches the literal text "cat" anywhere in a string
/hello world/gMatches the exact phrase including the space
Exercise
Write a pattern that matches the word "regex" (case-sensitive, lowercase only).
Your pattern: