Regex Quiz
Questions: 16 · 10 minutes
1. With its default greedy behavior, what is the first match of /a.*b/ in ""a1b2b""?
a1b
a1b2b
1b2b
b2b
2. What is the first text matched by /\d+/ in the string ""Order 507 ready""?
Order
5
507
Order 507
3. Why does /^Hi/m match the string ""Bye\nHi""?
The m flag lets ^ match at the start of a line
The caret ignores all text before the letters H and i
A pattern without a dot automatically skips the first line
The m flag makes matching case-insensitive
4. Which input is a complete match for /^(cat|dog)$/?
The combined word “catdog”
The capitalized word “Dog”
The lowercase word “dog”
The plural word “dogs”
5. In JavaScript-style regex syntax, which string is matched by /^cat$/?
The phrase “a cat”
The exact string “cat”
The plural word “cats”
The word “cat” followed by a newline and “dog”
6. What kind of character does \s commonly match?
Any character except whitespace
Any lowercase letter
A punctuation mark only
A whitespace character such as a space or tab
7. Which input contains a match for /\bcat\b/?
concatenate
cat2
_cat_
A cat!
8. What is the first match of the lazy pattern /a.*?b/ in ""a1b2b""?
a1b
1b
a
a1b2b
9. Which single character is matched by /[A-F]/?
Uppercase D
Lowercase d
Uppercase G
The digit 7
10. The regex /(\d{4})-(\d{2})-(\d{2})/ matches ""2025-08-17"". What text is stored in capture group 2?
2025
08
17
2025-08-17
11. Which feature allows /^hello$/i to match the string ""HELLO""?
The start-of-string anchor
The end-of-string anchor
The delimiters surrounding the pattern
The case-insensitive i flag
12. Which string is matched completely by /^\d{3}-\d{2}$/?
12-345
12345
123-45
123-456
13. Which pair of strings is matched completely by /^colou?r$/?
“colours” and “color”
“colouur” and “colour”
“colo” and “color”
“color” and “colour”
14. Which pattern requires a string to end with the literal text "".txt""?
A wildcard dot followed by txt, with no end anchor
An escaped literal dot followed by txt and an end anchor
An escaped literal dot followed by txt, with no end anchor
The letters txt followed by a start anchor
15. What is the first match of /[^0-9]+/ in the string ""123abc456""?
123
456
abc
123abc
16. When /foo(?=bar)/ is executed on ""xxfoobarxx"", what text does the full match contain?
foo
bar
An empty string
foobar