Which metacharacter is used to specify optional characters in a regular expression in Ruby?
A. *
B. +
C. ?
D. .
Answer: Option C
What does the =~ operator do in Ruby when used with regular expressions?
A. Evaluates the regular expression
B. Compares two regular expressions
C. Matches a string against a regular expression
D. Assigns a regular expression to a string
Which method is used to find the first occurrence of a pattern in a string in Ruby?
A. String#search
B. String#find
C. String#find_pattern
D. String#match
What does the /\A anchor represent in a regular expression in Ruby?
A. Matches one or more occurrences of the previous character
B. Matches any character except a newline
C. Matches the start of a string
D. Matches the end of a string
What is the purpose of the + quantifier in a regular expression in Ruby?
A. Matches zero or one occurrence of the preceding character
B. Matches zero or more occurrences of the preceding character
C. Matches exactly n occurrences of the preceding character
D. Matches one or more occurrences of the preceding character
Join The Discussion