What does the caret symbol (^) signify in a regular expression?
It signifies the start of a string.
What does the dollar sign symbol ($) signify in a regular expression?
It signifies the end of a string.
True or False: The dot (.) in a regular expression matches any single character except newline characters.
True.
What does the asterisk (*) symbol do in a regular expression?
It matches zero or more occurrences of the preceding element.
Fill in the blank: The plus sign (+) matches _____ occurrences of the preceding element.
one or more.
Which escape character is used to match special characters in a regular expression?
The backslash (\) is used to escape special characters in regular expressions.
For example, to match a literal period (.) instead of the “any character” wildcard, you’d write \.. Similarly, \* matches a literal asterisk, \? matches a literal question mark, and so on.Backslash ().
What is the purpose of parentheses () in a regular expression?
They are used to group expressions and capture matched substrings. A part of a regular expression that is enclosed in parentheses (subexpression) counts as a single element as far as the operators following it are concerned.
What does the question mark (?) signify in a regular expression?
It makes the preceding element optional, matching zero or one occurrence.
True or False: The curly braces ({}) are used to specify the exact number of occurrences of a preceding element.
True.
What does the expression [abc] match?
It matches any single character ‘a’, ‘b’, or ‘c’.
What does the expression [^abc] match?
It matches any single character except ‘a’, ‘b’, or ‘c’.
Multiple choice: Which of the following is a valid way to match a digit in a regular expression?
\d
What does the expression \D match?
It matches any character that is not a digit.
Fill in the blank: The expression \s matches any _____ character.
whitespace.
What does the expression \S match?
It matches any character that is not a whitespace.
What does the expression \w match?
It matches any word character (alphanumeric plus underscore).
What does the expression \W match?
It matches any character that is not a word character.
True or False: The vertical bar (|) is used to denote alternation in regular expressions.
True.
What is the purpose of the ‘g’ flag in a regular expression?
It signifies a global search, finding all matches rather than stopping after the first.
What does the ‘i’ flag do in a regular expression?
It makes the search case-insensitive.
What is the purpose of the ‘m’ flag in a regular expression?
It allows the caret (^) and dollar sign ($) to match the start and end of each line in a multiline string.
What is this a regex pattern for?
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}
email address
What does the expression {n,m} specify in a regular expression?
It matches between n and m occurrences of the preceding element.