12.11. Practice Problems - Regular Expressions¶
Construct a regex that matches both cat
and cats
.
Construct a regex that matches abc
followed by zero to many digits (0-9).
Construct a regex that matches both gray
and grey
.
Construct a regex that matches br
followed by any single character except for a new line and then a 3
.
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
Construct a regex that matches t.forward
.
Construct a regex that matches a word that starts with an uppercase letter followed by at least one lowercase letter, like “Apple”, “Banana”, or “Carrot”.
Construct a regex that matches eight word characters (letter, digit, or underscore).
Construct a regex that matches one or more lowercase letters (a-z) followed by a space character and then two to four digits.
Construct a regex to capture numbers with 5-7 digits. For example: 48105, 103028, 1234567.
Construct a regex that captures strings that have two digits followed by a period and then four letters from a to z.