Section 1: True/False Questions
1. The i flag in a regular expression makes the pattern case-insensitive.
The i flag stands for "ignore case".
True - The i flag makes the regex match both uppercase and lowercase letters.
2. The g flag causes the regex to stop after finding the first match.
The g stands for "global".
False - The g flag makes the regex find all matches, not just the first one.
3. The * quantifier matches zero or more occurrences of the preceding element.
Think about how many times the preceding character can appear.
True - The * matches 0 or more occurrences.
4. The ? quantifier matches exactly two occurrences of the preceding element.
The ? makes something optional.
False - The ? matches 0 or 1 occurrence (makes it optional).
5. The + quantifier matches one or more occurrences of the preceding element.
Compare this to * which includes zero occurrences.
True - The + requires at least one occurrence.
6. In JavaScript, regular expression literals are enclosed in forward slashes /.
Think about the syntax: /pattern/flags
True - JavaScript regex literals use forward slashes as delimiters.
7. The character class [acg] matches any single character that is 'a', 'c', or 'g'.
Square brackets define a character class.
True - Character classes match any one of the characters inside the brackets.
8. The pattern [a-z] matches only lowercase letters from 'a' to 'z'.
The hyphen in a character class indicates a range.
True - The a-z range matches lowercase letters only.
Section 2: Multiple Choice Questions
Section 3: Fill in the Blank Questions
17. To make a regex pattern case-insensitive, you add the ____ flag.
This flag stands for "ignore case".
i
18. The ____ flag is used to find all matches in a string, not just the first one.
This flag stands for "global".
g
19. The ____ quantifier matches zero or more occurrences of the preceding element.
This symbol is commonly called an asterisk or star.
*
20. To make a character optional in a regex, use the ____ quantifier.
This symbol is a question mark.
?
21. The ____ quantifier matches one or more occurrences of the preceding element.
This symbol is a plus sign.
+
22. In JavaScript, regex literals are enclosed in ____ characters.
These are the same characters used in division and URLs.
/
23. To match any one of the characters a, c, or g, you would write ____.
Use square brackets to create a character class.
[acg]
24. To match any lowercase letter from a to z, write ____.
Use a hyphen to indicate a range within square brackets.
[a-z]