Regular Expressions
The small language for describing text patterns, used in search boxes, log tools, editors, scripts and validation: how to read and write patterns, how engines differ, and how to keep patterns correct, readable and fast.
18 pages 78 glossary terms Linux+ Linux Essentials
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
- 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.
- 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.
- 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}.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 10Search and ReplaceUsing regular expressions to change text: replacement strings with group references, replacing with a function, splitting text, and doing bulk edits safely.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
Regular Expressions glossary
Short definitions of the terms used in this topic. The full glossary covers every topic.