$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #117

Which fix removes the bug?

import re
if re.match(r'\d+', value):
    accept(value)
  1. Anchor the whole value: r'\d+$'
  2. Anchor the whole value: r'^\d+'
  3. Change re.match to re.search here
  4. Compile the pattern before matching it
match only anchors the start, so '12abc' is accepted; add $ to require the full string.
Play Problem Solving ▸