Character Classes
[a-j] any character a-j (ranges ar asciicographical) [ab%*pqZB] any of a, b, %, p, q, Z or B (list character class) [a-z580] inside the brackets metacharacters: - indicates a range [ and ] bound a list character class To defang magic: use a \. [\[42up] matches [, 4, 2, u, p.
SNOTty Character Classes
[^a-z] anything BUT a-z. [^aeiouy] anything but a, e, i, o, u, y ^ must appear first or a hat's just a hat.Special character classes . any character except for \n. ^ beginning of string $ end of string \d digit
Regular Expressions There are dialects for Python, Java, and JavaScript.
Juxtaposition "and then immediately"
[abc][def][ghi] beg, being
phone number
xxx-xxx-xxxx
2-9
digit
digit
-
2-9
digit
digit
-
digit
digit
digit
digit
^[2-9][0-9][0-9]-[2-9][0-9][0-9]-[0-9][0-9][0-9][0-9]$
^([2-9][0-9]{2}-){2}[0-9]{4}$
^([2-9]\d{2}-){2}\d{4}$
match an integer
^[+-]?\d+$
function isANaturalNumber(s)
{
return /^\d+$/.matches(s);
}
Multiplicity operators:
{n} n times
{n,} n or more times operator
{m,n} at least m but not more than n times
? once or not at all
* zero or more time
+ one or more times
These are postfix unary operators.
Multplicity forst
then juxtaposition
use ( and ) to override