← 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"))
- A.asha@home
- B.home@asha
- C.\2@\1
- 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 →