56 / 80 · 12 Programming for QA · Regex and Parsing← prev⊞ allnext →☰ Read as one page
7.5Regex Building Blocks
| Symbol | Meaning | Example |
|---|---|---|
. |
Any character | a.c matches "abc", "a1c" |
\d |
Digit | \d{3} matches "123" |
\w |
Word character (letter, digit, underscore) | \w+ matches "hello_world" |
\s |
Whitespace | \s+ matches spaces, tabs, newlines |
\b |
Word boundary | \berror\b matches "error" but not "errors" |
^ |
Start of string | ^Hello matches "Hello world" |
$ |
End of string | world$ matches "Hello world" |
* |
Zero or more | ab*c matches "ac", "abc", "abbc" |
+ |
One or more | ab+c matches "abc", "abbc" (not "ac") |
? |
Zero or one | colou?r matches "color" and "colour" |
{n,m} |
Between n and m | \d{2,4} matches "12", "123", "1234" |
[abc] |
Character class | [aeiou] matches any vowel |
[^abc] |
Negated class | [^0-9] matches non-digits |
(...) |
Capture group | (\d+)-(\d+) captures "123" and "456" from "123-456" |
(?:...) |
Non-capture group | Groups without capturing |
\1 |
Back reference | Matches the first captured group |