Glossary · Programming

Regex (Regular Expression)

A regular expression is a compact pattern language for matching, searching and replacing text, used for validation, parsing and log filtering.

Updated October 6, 2026

A regex (regular expression) is a sequence of characters that defines a search pattern. You use it to find, validate, extract or replace text, for example to check that a string looks like an email address or to pull status codes out of a log file.

Why it matters

Regex turns many lines of string-handling code into one pattern and is built into most languages, editors and command-line tools such as grep. Syntax details vary slightly between engines, so a pattern should be tested in the engine you will actually use.

Example

Pattern:  ^(\d{3}) (GET|POST) (\S+)$
Text:     404 GET /missing-page
Groups:   1 = 404, 2 = GET, 3 = /missing-page

\d{3} matches exactly three digits, (GET|POST) matches either word, \S+ matches non-space characters, and ^ and $ anchor the start and end of the line.

Common mistakes

  • Forgetting to escape special characters such as ., which matches any character, not a literal dot.
  • Writing nested quantifiers like (a+)+ that cause catastrophic backtracking and freeze the program on certain input.
  • Using regex to fully validate emails or parse HTML, where a dedicated parser or library is safer.

Get notified when this term updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.