Regular Expression Syntax
Problem
You need to learn the syntax of regular expressions.
Solution
Consult Chapter 4 for a list of the regular expression characters that the Apache Regular Expression API matches.
Table 4-2. Regular expression syntax
|
Subexpression |
Will match: |
Notes |
|---|---|---|
|
General | ||
|
|
The letter | |
|
|
Start of line/string | |
|
|
End of line/string | |
|
|
Any one character | |
|
|
“Character class”; any one character from those listed | |
|
|
Any one character not from those listed | |
|
Normal (greedy) multipliers (“greedy closures”) | ||
|
|
Multiplier (closure) for from | |
|
|
Multiplier for from | |
|
|
Multiplier for 0 up to | |
|
|
Multiplier for 0 or more repetitions |
Short for |
|
|
Multiplier for 1 or more repetitions |
Short for |
|
|
Multiplier for 0 or 1 repetitions |
Short for |
|
Reluctant (non-greedy) multipliers (“reluctant closures”) | ||
|
|
Reluctant multiplier: 0 or more | |
|
|
Reluctant multiplier: 1 or more | |
|
|
Reluctant multiplier: 0 or 1 times | |
|
Alternation and grouping | ||
|
|
Grouping | |
|
|
Alternation | |
|
Escapes and shorthands | ||
|
|
Escape character: turns metacharacters off, and turns following
alphabetics ( | |
|
|
Tab character | |
|
|
Character in a word |
Use |
|
|
Numeric digit |
Use |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access