# Bad
path = "C:\\Users\\root"
# Good
path = r"C:\Users\root"
# Bad
regex = "\\^\\(\\?P<major>0\\|\\[1\\-9\\]\\\\d\\*\\)\\\\\\.\\(\\?P<minor>0\\|\\[1\\-9\\]\\\\d\\*\\)\\\\\\.\\(\\?P<patch>0\\|\\[1\\-9\\]\\\\d\\*\\)\\(\\?:\\-\\(\\?P<prerelease>\\(\\?:0\\|\\[1\\-9\\]\\\\d\\*\\|\\\\d\\*\\[a\\-zA\\-Z\\-\\]\\[0\\-9a\\-zA\\-Z\\-\\]\\*\\)\\(\\?:\\\\\\.\\(\\?:0\\|\\[1\\-9\\]\\\\d\\*\\|\\\\d\\*\\[a\\-zA\\-Z\\-\\]\\[0\\-9a\\-zA\\-Z\\-\\]\\*\\)\\)\\*\\)\\)\\?\\(\\?:\\\\\\+\\(\\?P<buildmetadata>\\[0\\-9a\\-zA\\-Z\\-\\]\\+\\(\\?:\\\\\\.\\[0\\-9a\\-zA\\-Z\\-\\]\\+\\)\\*\\)\\)\\?\\$"
# Good
regex = r"^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
Explanation
raw strings are more readable and maintainable for humans in many cases.
Prior art:
Example