# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^\/ignition-interlock-device\/([a-z]*?)\/(locations)?\/smart-start-of-([a-z0-9-]*?)(\/)?$"
test_str = ("/ignition-interlock-device/colorado/locations/smart-start-of-alamosa/\n"
"/ignition-interlock-device/colorado/locations/smart-start-of-auburn-2/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-beverly/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-boca-raton-2/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-brownsville/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-camrose/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-carbondale/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-carson-city/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-centereach/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-charleston-2/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-charleston/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-danielson/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-defuniak-springs/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-deland-2/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-durango/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-farmington/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-framingham/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-gallatin/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-gresham/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-gypsum/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-hialeah/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-holly-hill-2/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-honolulu-3/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-huntington/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-huntsville/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-kennesaw/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-kennewick/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-kissimmee-2/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-la-crosse/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-laramie/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-lawton/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-longwood/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-malden/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-mckinney/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-medford/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-middletown-2/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-middletown/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-mildura/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-new-port-richey/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-norco/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-ocala-2/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-palm-bay-2/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-palm-bay/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-panama-city-2/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-port-charlotte-2/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-richmond-3/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-saint-paul-2/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-san-marcos/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-santa-ana/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-show-low/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-staunton/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-tallahassee-2/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-titusville/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-uppsala-2/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-van-wert/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-west-monroe/\n"
"/ignition-interlock-device/florida/locations/smart-start-of-west-palm-beach-2/")
subst = "/locations/?location_redirect=$3&state=$1"
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0, re.IGNORECASE | re.MULTILINE)
if result:
print (result)
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html