regular expression
A regular expression is a compact search pattern made of symbols that allows a computer to find specific forms within text, such as phone numbers or email addresses.
In plain terms
With a simple search (Ctrl+F), you look for a specific word, such as "Kovács". With a regular expression, you search for a pattern: "four digits, hyphen, two digits, hyphen, two digits". This way, you find all dates written in this format (for example, 2026-11-10) at once, regardless of the specific date.
It is like a postman who is not looking for one specific letter but for every envelope with a four-digit postcode. The postman does not know the content, only the format, and sorts by that.
The pattern consists of strange symbols, so it seems intimidating at first: \d means 'a digit', and + means 'one or more of the previous'. In return, a single line can accomplish what would take hours by hand: data collection, form verification, and mass replacement.
Unlike language models, regex does not 'understand' text or guess: it always returns the same result for the same text. That is why coding agents use it when they need to search many files quickly and accurately.
How it works
- You write the pattern: letters and numbers represent themselves, while special characters represent rules. For example, \d{4} means exactly four digits in a row.
- The program attempts to fit the pattern character by character, starting from the beginning of the text.
- If it gets stuck at some point, most programs backtrack and try another option, or restart one character further on. Some matching engines (such as those of the Go and Rust languages) work without backtracking: they cannot slow down dramatically, but in return they lack some advanced features.
- Where the pattern matches completely, it signals a hit. This part can be highlighted, collected, or replaced with something else.
- With parentheses, you can mark individual parts of a result separately, allowing you to extract the year, month, and day from a date, for example.
An everyday example
When a web form instantly flags an input in red as an 'invalid email address' or 'password must contain a number', a regular expression is often checking what you typed in the background. You use the same mechanism in the Find and Replace dialog of Google Sheets (if you enable this option), as well as in the REGEX-prefixed functions of Google Sheets and Microsoft 365 Excel. Word's wildcard search operates on a similar principle but uses its own, simpler notation.
Who is affected
A common misconception
Limits and risks
- Hard to read: a longer pattern is often not understood even by its own author a few weeks later, so it is easy to leave errors in it.
- It checks only the format, not the reality: a formally correct email address can still be non-existent.
- A poorly written pattern (regular expression) can slow down dramatically on certain texts because of excessive backtracking, and may even paralyze an entire service.
- The notation varies slightly by program, so the same pattern does not work identically everywhere.
- AI-written regex must also be tested on real examples, because it often misses edge cases (accents, spaces, foreign formats).
Similar, but not the same
- wildcard character – The asterisk and question mark used in filenames (e.g., *.pdf) are much simpler and less powerful than regular expressions.
- semantic search – Semantic search finds semantically related texts based on meaning, while regex examines only the exact character pattern.
- prompt – A prompt is a plain-language instruction to a language model that interprets it, while regex is a strict formal notation that the machine executes literally.
Related concepts
pattern matching, text processing, formal language
character class, kvantor, capturing group
wildcard character, input validation, command line, semantic search, data cleaning, coding agent, szkript
A brief history
The theoretical foundations of the concept were written down by American mathematician Stephen Kleene in 1951 in a research report, which was published in print in 1956. Ken Thompson put it into practice: in 1968 he published a search algorithm for it and integrated it into the QED, then the Unix ed text editor. The grep command also originates from here.
Where things stand
By the end of 2026, almost every programming language, most code editors, and major spreadsheet applications (Google Sheets and the Microsoft 365 version of Excel) support it. Patterns are increasingly written by an AI assistant or coding agent instead of a human, but verification remains your responsibility.
Also known as
regular expression · regex · regexp · RegEx · regular expression · regular expression · regex minta · RE
Sources
This entry was machine-edited and has undergone machine expert review; the “In the news” section updates automatically from Agent Age stories.