How to regex replace and get the number of replacements with re.subn()

Опубликовано: 29 Сентябрь 2024
на канале: Pybites
98
8

Today a quick video on regex string replacements.

You can use re.sub() for that, and with re.subn() you get the "number_of_subs_made" in addition to the replaced string. We show a quick example in this short.

Docs:
https://docs.python.org/3/library/re....

Raw string notation:
https://docs.python.org/3/library/re....

Related Bite exercise where you can put this in practice:
https://codechalleng.es/bites/106/

For more tips check out our book:
https://pybit.es/tips/

---
Learn more about Pybites / what we do: https://pybit.es

Get our weekly developer / mindset emails: https://pybit.es/friends/

Join our Slack community: https://pybit.es/community/

And last but not least, we appreciate any feedback to make our YouTube content better 💡
https://form.jotform.com/230941798741062 🙏