Learn regular expressions in about 55 minutes
regexregular-expressionsstring-processingtutorial
Abstraction: Concise tutorial covering core regex syntax from literals to capture groups
Key points:
- Character classes:
.(any char),[abc],[a-z],\d(digit),\w(word char[0-9A-Za-z_]),\s(whitespace), and their negations\D,\W,\S - Multipliers:
{n},{m,n},?(0 or 1),(0+),+(1+); all greedy by default; append?to make non-greedy (e.g.,.?) - Capture groups with
()numbered left-to-right; back-references\1,\2usable in both replacement expressions and matching (e.g.,([abc])\1matchesaa,bb,cc) - Anchors:
\bword boundary (zero-width),^start-of-line,$end-of-line; some implementations have\A/\zfor text boundaries - Do not use regex to parse HTML/XML (use a parser), validate email addresses (only sending verifies), or validate people's names
- In languages like Java, string escaping adds a layer on top of regex escaping; use
Pattern.quote()to escape dynamic input safely
Connections: Regular Expressions ยท String Processing
Source: http://qntm.org/files/re/re.html