LearnFrenzy
Sign in Take a free test

Regular Expressions · Regular Expressions MCQ · Question 3

Why raw strings for patterns? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

Why are regex patterns usually written as raw strings like r"\bword\b"?

  • A So backslashes reach the regex engine unchanged instead of being treated as Python escapes Correct
  • B Raw strings run faster
  • C The re module accepts only raw strings
  • D They make matching case-insensitive
Correct Answer: Option A

Without r, "\b" is a backspace character, so the pattern would not mean "word boundary".

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links