bbelderbos,
@bbelderbos@fosstodon.org avatar

In you can use sub() from the "re" module to do regex string replacing.

If you want to keep a count of the number of replacements done as well, you can use subn() which returns a tuple of the new (replaced) string and the number of replacements made.

For example:

bbelderbos,
@bbelderbos@fosstodon.org avatar

Practice #python regex on our platform with this learning path: https://codechalleng.es/bites/paths/regex

  • All
  • Subscribed
  • Moderated
  • Favorites
  • python
  • tacticalgear
  • DreamBathrooms
  • InstantRegret
  • magazineikmin
  • osvaldo12
  • Youngstown
  • ngwrru68w68
  • slotface
  • everett
  • rosin
  • thenastyranch
  • kavyap
  • GTA5RPClips
  • modclub
  • JUstTest
  • normalnudes
  • cubers
  • ethstaker
  • mdbf
  • Durango
  • khanakhh
  • tester
  • provamag3
  • cisconetworking
  • Leos
  • anitta
  • megavids
  • lostlight
  • All magazines