Created
November 27, 2017 19:25
-
-
Save danmaps/f9917935dc4a861d050aa2625c6b6295 to your computer and use it in GitHub Desktop.
python regular expressions sample for replacing strings using wildcards
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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