Skip to content

Instantly share code, notes, and snippets.

Created May 26, 2021 11:36
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Migrate Bootstrap 4 to 5 via RegEx
# table for regex replacements
[r"ml(-\d)", r"ms\1"],
[r"mr(-\d)", r"me\1"],
[r"pl(-\d)", r"ps\1"],
[r"pr(-\d)", r"pr\1"],
[r"data-toggle=([\"'](?:collapse|dropdown|tab)[\"'])", r"data-bs-toggle=\1"],
[r"data-target=", r"data-bs-target="],
["float-left", "float-start"],
["float-right", "float-end"],
["text-left", "text-start"],
["text-right", "text-end"],
["border-left", "border-start"],
["border-right", "border-end"],
["text-monospace", "font-monospace"],
["no-gutters", "g-0"],
def replaceText(text):
for regex in tabRegEx:
#match ="(?<=\W)"+regex[0]+r"(?=\W)", text)
#if match: print(regex[0], match[0])
text = re.sub(r"(?<=\W)"+regex[0]+r"(?=\W)", regex[1], text)
return text
def processFile(filename):
with open(filename, 'r') as file:
text =
text = replaceText(text)
if text=="": return # abbort on error
with open(filename, 'w') as file:
import sys
import re
# read all files and replace
for filename in sys.argv[1:]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment