How to use this topic

The first ten pages teach the language itself: what regular expressions are, literals and escaping, character classes, quantifiers, anchors, groups, alternation, lookaround, flags, and search and replace. The next three show the same ideas in real tools: the differences between regex flavors, grep, sed and awk on the command line, and Python, JavaScript and PHP side by side. The last four are practice: patterns for logs, addresses and dates, validating input, catastrophic backtracking, and testing. The topic ends with a Regex Tester where you try patterns yourself.

The examples run for real, in Python, JavaScript, PHP and the shell, and show their exact output, so you can see where engines agree and where they differ. A short introduction with grep is in Searching with grep, find and Regular Expressions; this topic goes much further.

There is no certification for regular expressions. The page on grep, sed and awk is marked Linux+ and Linux Essentials, because both Linux exams include regular expressions on the command line.

Learning path

  1. 01What Are Regular Expressions?What a regular expression is, where you meet them in IT work, where they came from, and when a regex is the wrong tool for the job.Beginner
  2. 02Literals, Metacharacters and EscapingHow a pattern is read: ordinary characters that match themselves, the metacharacters with special meaning, the dot, escaping with a backslash, and raw strings in code.Beginner
  3. 03Character Classes and ShorthandsMatching one character out of a set: brackets, ranges and negation, the shorthands \d, \w and \s, POSIX classes, and Unicode categories such as \p{L}.Beginner
  4. 04Quantifiers: Greedy, Lazy and PossessiveRepeating parts of a pattern with *, +, ? and {n,m}, why quantifiers are greedy by default, how lazy and possessive versions behave, and the classic overmatching mistakes.Beginner
  5. 05Anchors and Word BoundariesMatching positions instead of characters: ^ and $, the start and end of the whole text, multiline mode, word boundaries, and why anchors turn a search into a validation.Beginner
  6. 06Groups, Captures and BackreferencesGrouping parts of a pattern, capturing what they matched, naming groups, non-capturing groups, and backreferences that match the same text again.Intermediate
  7. 07Alternation and PrecedenceChoosing between alternatives with |, how far an alternative reaches, why the order of alternatives matters in backtracking engines, and how to group them correctly.Intermediate
  8. 08Lookahead and LookbehindChecking what comes before or after a position without consuming it: positive and negative lookahead and lookbehind, practical uses, and the limits in each engine.Intermediate
  9. 09Flags and ModesChanging how a pattern behaves: case-insensitive, multiline and dotall modes, verbose patterns with comments, Unicode mode, global and sticky matching, and inline flags.Intermediate
  10. 10Search and ReplaceUsing regular expressions to change text: replacement strings with group references, replacing with a function, splitting text, and doing bulk edits safely.Intermediate
  11. 11Regex FlavorsWhy the same pattern can behave differently: POSIX basic and extended syntax, PCRE, Python, JavaScript, .NET and RE2-style engines, and a table of the differences that bite.Intermediate
  12. 12Regex on the Command Line: grep, sed and awkSearching and editing text from the shell: grep with basic, extended and Perl-style patterns, printing only the match, sed substitutions, and field matching in awk.BeginnerLinux+Linux Essentials
  13. 13Regex in Python, JavaScript and PHPThe same tasks in three languages: finding, extracting, replacing and splitting with Python's re module, JavaScript's RegExp and PHP's preg functions, and their traps.Intermediate
  14. 14Practical Patterns: Logs, IP Addresses and DatesPatterns for everyday IT text: pulling fields out of log lines, finding IP addresses, matching dates and times, and checking the results with a real parser.Intermediate
  15. 15Validating Input: Email, Phone Numbers and URLsWhat regular expressions can and cannot check in user input: email addresses, phone numbers, URLs and postal codes, and when a parser or a confirmation step is the better answer.Intermediate
  16. 16Performance and Catastrophic BacktrackingWhy some patterns take seconds or forever: how backtracking works, catastrophic backtracking and ReDoS, real outages it caused, and how to write and run patterns safely.Advanced
  17. 17Testing, Debugging and ReadabilityKeeping regular expressions correct and maintainable: building patterns step by step, test cases for matches and non-matches, verbose mode and comments, online testers, and checking AI-written patterns.Intermediate
  18. 18Regex TesterTry patterns yourself: type a regular expression and some text, and see every match, its groups and the result of a replacement as you type, using your browser's JavaScript engine.Beginner

Regular Expressions glossary

Short definitions of the terms used in this topic. The full glossary covers every topic.