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

What does this print? (code)

What does this print?

import re
print(re.sub(r"(\w+)@(\w+)", r"\2@\1", "asha@home"))
  1. A.asha@home
  2. B.home@asha
  3. C.\2@\1
  4. D.home asha
Answer & explanation

Correct answer: home@asha

\1 and \2 in the replacement are the two captured groups, swapped here.

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 →