nerdexam
Cisco

210-255 · Question #8

Which string matches the regular expression r(ege)+x?

The correct answer is B. regeegex. The pattern r(ege)+x requires the group 'ege' to repeat one or more times between 'r' and 'x', and 'regeegex' satisfies this with two consecutive 'ege' repetitions.

Security Monitoring

Question

Which string matches the regular expression r(ege)+x?

Options

  • Arx
  • Bregeegex
  • Cr(ege)x
  • Drege+x

How the community answered

(24 responses)
  • A
    4% (1)
  • B
    79% (19)
  • C
    13% (3)
  • D
    4% (1)

Why each option

The pattern r(ege)+x requires the group 'ege' to repeat one or more times between 'r' and 'x', and 'regeegex' satisfies this with two consecutive 'ege' repetitions.

Arx

rx contains no 'ege' group at all, but the + quantifier requires at least one occurrence of the group, so rx cannot match.

BregeegexCorrect

The regex r(ege)+x matches 'r', then one or more occurrences of the capturing group 'ege', then 'x'. The string 'regeegex' decomposes as r + ege + ege + x - the substring 'egeege' is exactly two back-to-back occurrences of 'ege', satisfying the (ege)+ requirement and producing a valid full match.

Cr(ege)x

r(ege)x contains literal parenthesis characters, which are not present in the regex pattern where parentheses serve as grouping metacharacters rather than literals.

Drege+x

rege+x is a different regex where + applies only to the single character 'e', not to the group 'ege', so it is a distinct pattern and not a valid match for r(ege)+x.

Concept tested: Regex capturing group with one-or-more quantifier

Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Groups_and_backreferences

Topics

#regular expressions#regex quantifiers#pattern matching#grouping

Community Discussion

No community discussion yet for this question.

Full 210-255 Practice