🎙 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 2 of 10

Why should regex patterns be written as raw strings like r"\d"?

Why should regex patterns be written as raw strings like r"\d"?

  1. A.Raw strings run faster
  2. B.So Python does not change backslash sequences before re sees them
  3. C.re only accepts raw strings
  4. D.To make the pattern case-insensitive
Answer & explanation

Correct answer: So Python does not change backslash sequences before re sees them

Without r, a sequence like \b becomes a backspace character instead of a word boundary.

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 →