What Is Regex?
Regular expressions (regex or regexp) are sequences of characters that define search patterns. They are a fundamental tool in programming for string searching, data validation, text extraction, and find-and-replace operations. Every major language — JavaScript, Python, Java, PHP, Go, Ruby — has native regex support.
A regex pattern like \d3-\d4 matches a phone segment with 3 digits, a hyphen, and 4 digits. Patterns can range from simple literals to complex expressions with lookaheads, named groups, and Unicode properties.
Regex Flags Reference
| Flag | Name | Effect |
|---|---|---|
| g | Global | Find all matches |
| i | Ignore Case | Case insensitive |
| m | Multiline | ^ $ match line ends |
| s | Dot All | Dot matches newline |
| u | Unicode | Full Unicode support |
| y | Sticky | Match from lastIndex |