# Regular Expression (Regex)

> A short pattern for text you want to find, like three digits and a dash.

**Field:** Software Development  
**Category:** Files & Formats  
**Also known as:** Regex, RegExp, Regular Expressions

## Think of it like

Think of it like a search with blanks. Find three digits, a dash, then four digits, whatever they are.

## Definition

A regex is a short pattern that describes text to look for. It can match a fixed word, or a shape like any three digits followed by a dash. Signs like \d stand for a digit, and {3} means three of them. Programs use regex to find, check or replace text, like checking that an email looks valid. Most languages and code editors support it.

## Example

Emma needs every phone number in a long page. One regex finds all 40 of them in a second.

## Example code

```python
import re
print(re.findall(r"\d{3}-\d{4}", "Call 555-0142 or 555-0199"))
# ['555-0142', '555-0199']
```

The pattern finds both numbers, no matter what digits they have.

## Why it matters

One line of regex can do the work of many lines of code. It finds or checks text.

## Common mistake

Writing one huge regex nobody can read. Split it up or add comments, or the next person will not dare touch it.

## Three principles

- **A pattern, not a word.** It describes a shape of text.
- **Find, check, replace.** Three common jobs.
- **Keep it short.** Long ones are hard to read.

## Related terms

- [String](https://learn.benibix.com/term/development/string)
- [Syntax](https://learn.benibix.com/term/development/syntax)
- [Code Editor](https://learn.benibix.com/term/development/code-editor)
- [Python](https://learn.benibix.com/term/development/python)
- [Escape Character](https://learn.benibix.com/term/development/escape-character)
- [ripgrep (rg)](https://learn.benibix.com/term/development/ripgrep)

## Taught in

- [Regular Expressions (Regex)](https://learn.benibix.com/learn/development-formats/regular-expressions-regex): File Formats, 11/11

---

Source: https://learn.benibix.com/term/development/regular-expression
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
