Practice Problems - Mixed-up Code¶
Please answer the following problems to the best of your ability without any outside help. You can stop working on a problem after you worked on it for about four minutes without solving it.
Problems¶
Loading a dynamic question ...
Selecting from: hparsons_lg_regex_1_hparsons
Loading a dynamic question ...
Selecting from: hparsons_lg_regex_2_hparsons
Loading a dynamic question ...
Selecting from: hparsons_lg_regex_3_hparsons
Loading a dynamic question ...
Selecting from: hparsons_lg_regex_4_hparsons
Loading a dynamic question ...
Selecting from: hparsons_lg_regex_5_hparsons
Loading a dynamic question ...
Selecting from: hparsons_lg_regex_6_hparsons
Please write a regex that would match both word “gray” and “grey”.
Please write a regex that would match a word that starts with an uppercase letter and followed by at least one lowercase letters, like “Apple”, “Banana”, or “Carrot”.
Please write a regex to capture numbers with 5-7 digits. For example: 48105, 103028, 1234567.
Capture words that start with a vowel (a, e, i, o, u), but end with a consonant (any letters that are not a, e, i, o, u). For example, it should match “unicorn”, “it”, and “element”.
Please write a regex to replace the ‘YOUR_REGEX’ below to match any price in the form of $3.45 or $23.32 or $400. Note that we are using re.findall(), so please make sure your regex would return the full match string.
def find_price(content):
return re.findall('YOUR_REGEX', content)
Please write a regex to capture a URL that only consists of characters, numbers, underscore, and dots. For example: www.abc.com, def_ghi.com, a678.cn Note that dots(“.”) should not appear consecutively, and should not appear as the first or last character. The dot must appear at least once.
What to do next¶
Click on the following link to go to the post test: Post Test