Skip to content

Instantly share code, notes, and snippets.

@danmaps
Created November 27, 2017 19:25
Show Gist options
  • Save danmaps/f9917935dc4a861d050aa2625c6b6295 to your computer and use it in GitHub Desktop.
Save danmaps/f9917935dc4a861d050aa2625c6b6295 to your computer and use it in GitHub Desktop.
python regular expressions sample for replacing strings using wildcards
import re
strings = ['abc@1@xyz','abc@2@xyz','abc@789@xyz','abc@defghijklmno@xyz']
for text in strings:
regextest = re.sub("@.*@",str(strings.index(text)),text) # .* means zero or more of any character
print regextest
'''expected output
abc0xyz
abc1xyz
abc2xyz
abc3xyz
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment