Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@TomoG29
Created April 30, 2023 10:04
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 TomoG29/4a7bf98e7eee7e4e10659899fa964fc6 to your computer and use it in GitHub Desktop.
Save TomoG29/4a7bf98e7eee7e4e10659899fa964fc6 to your computer and use it in GitHub Desktop.
str1 = "ababcdcd cdbacdba abcdabcd"
import re
str2 = re.sub("a","1",str1)
print(str2)
#1b1bcdcd cdb1cdb1 1bcd1bcd
print(re.sub("a","1",str1,4))
#1b1bcdcd cdb1cdb1 abcdabcd
print(re.sub("[a-c]","x",str1))
#xxxxxdxd xdxxxdxx xxxdxxxd
print(re.sub("[a-b]+c","z",str1))
#zdcd cdzdba zdzd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment