← 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"?
- A.Raw strings run faster
- B.So Python does not change backslash sequences before re sees them
- C.re only accepts raw strings
- 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 →