You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import re
rep = {"h1": "h2", "h2": "h3", "h3": "h4"} # define desired replacements here
# use these three lines to do the replacement
rep = dict((re.escape(k), v) for k, v in rep.items())
pattern = re.compile("|".join(rep.keys()))
#text = pattern.sub(lambda m: rep[re.escape(m.group(0))], text)
result = pattern.sub(lambda m: rep[re.escape(m.group(0))], "<h1>test1</h1>test1<h2>test2</h2>test2<h3>test3</h3>test3")
print(result)
The text was updated successfully, but these errors were encountered:
搜尋過程, 以"python replace different string simultaneously" 作為關鍵字, 參考 https://stackoverflow.com/questions/6116978/how-to-replace-multiple-substrings-of-a-string/6117042 中所提供的方法, 可以同時將 config/content.htm 中的 h 各往後推送一階.
The text was updated successfully, but these errors were encountered: