# Regex

> A compact pattern language for finding and checking pieces of text.

- Level: Intermediate
- Topics: Software
- URL: https://tidbit.legios.com.ar/regex/
- In Spanish: [Regex](https://tidbit.legios.com.ar/es/regex/)

A **regex** (regular expression) is a short pattern that describes a shape of text, so a program can find every piece of text with that shape. Instead of searching for one exact word, you describe what you want: "four digits, a dash, two digits". In regex that is written `\d{4}-\d{2}`, where `\d` means any digit and `{4}` means exactly four of the previous thing.

Regexes are everywhere text is processed. A signup form uses one to check that an email looks like an email. A spreadsheet or code editor uses them for powerful find-and-replace, like turning every date from `2026-10-17` into `17/10/2026` in one go. Programmers use them to pull order numbers out of emails, clean up messy data or scan logs for errors. Almost every programming language and many text tools support them.

Their power comes with a reputation for being hard to read. A pattern like `^[\w.+-]+@[\w-]+\.[\w.]+$` is dense, and small mistakes match too much or too little. Good practice is to keep patterns simple, test them against real examples with tools like regex101, and not use them for jobs they handle badly, such as fully parsing HTML.

## An analogy

Searching a phone book not for a name but for a description: "every surname that starts with Mac, followed by any letters, ending in -son". The regex is that description written in a tiny, strict shorthand.

## Keep in mind

- Describes a pattern of text, not one fixed word.
- Used to search, validate (like emails) and find-and-replace.
- Symbols like `\d` (digit) and `+` (one or more) build the pattern.
- Powerful but easy to get subtly wrong; test patterns on real data.

## Go deeper

- [Regular expressions guide (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions)
- [regex101, an online tester that explains each part](https://regex101.com/)
- [Regular expression on Wikipedia](https://en.wikipedia.org/wiki/Regular_expression)

## Related terms

- [Spreadsheet vs database](https://tidbit.legios.com.ar/spreadsheet-vs-database/): Why a company that runs on Excel eventually needs a real database.
- [IDE](https://tidbit.legios.com.ar/ide/): The app where programmers write, run and fix code, with all the tools in one window.
- [Programming language](https://tidbit.legios.com.ar/programming-language/): A precise, written language people use to give instructions to a computer.
- [HTML](https://tidbit.legios.com.ar/html/): The text format that describes what is on a web page: headings, paragraphs, links.
