200-201 · Question #389
What matches the regular expression r(ege)+x?
The correct answer is B. regeegex. The regular expression r(ege)+x matches strings starting with 'r', followed by one or more occurrences of the 'ege' sequence, and ending with 'x'.
Question
What matches the regular expression r(ege)+x?
Options
- Ar(ege)x
- Bregeegex
- Crx
- Drege+x
How the community answered
(31 responses)- B90% (28)
- C6% (2)
- D3% (1)
Why each option
The regular expression r(ege)+x matches strings starting with 'r', followed by one or more occurrences of the 'ege' sequence, and ending with 'x'.
`r(ege)x`, if interpreted as a literal string pattern, only contains one 'ege' occurrence, not 'one or more' as specified by the `+` quantifier.
The regular expression `r(ege)+x` means: 'r' matches the literal character 'r'; `(ege)` matches the literal sequence 'ege'; `+` indicates that the preceding group (ege) must occur one or more times; and 'x' matches the literal character 'x'. Therefore, 'regeegex' fits because it has 'r', followed by 'ege' twice (which is one or more times), and ends with 'x'.
`rx` does not contain the 'ege' sequence at all, violating the `(ege)+` requirement.
`rege+x` would match 'r', followed by 'eg' and then one or more 'e's, ending with 'x', which is different from one or more occurrences of the entire 'ege' sequence.
Concept tested: Regular expression syntax - repetition (+)
Source: https://learn.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions
Topics
Community Discussion
No community discussion yet for this question.