🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Regular Expressions in Python: all 10 questions

Quiz: Regular Expressions in Python · Question 3 of 10

Which function should you use to check that a whole input is a valid PIN code of 6 digits?

Which function should you use to check that a whole input is a valid PIN code of 6 digits?

  1. A.re.search(r"\d{6}", s)
  2. B.re.match(r"\d{6}", s)
  3. C.re.findall(r"\d{6}", s)
  4. D.re.fullmatch(r"\d{6}", s)
Answer & explanation

Correct answer: re.fullmatch(r"\d{6}", s)

Only fullmatch rejects extra characters before or after the six digits.

Can you get the rest right without peeking?

Take the timed Quiz: Regular Expressions in Python quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →