Skip to content

Instantly share code, notes, and snippets.

@myano
Created November 23, 2016 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myano/01428eddb097799a34b3c9466279d449 to your computer and use it in GitHub Desktop.
Save myano/01428eddb097799a34b3c9466279d449 to your computer and use it in GitHub Desktop.
import re
txt = 'some smoe msoe soem http://www.google.com/meep/peem/peme soMe sMoe Msoe soeM https://www.google.com/meep/peem/pmep/ soem msoe smoe some'
def my_replace(match):
if not str(match.group()).startswith('http'):
return re.sub('(?i)m', '_', match.group())
else:
return match.group()
print re.sub(r'\S+', my_replace, txt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment