import re
regex = re.compile(r"(?<=from..)(.*)(?=module)(.*)(module)")
test_str = ("import { service1 } from \"./module/1.service\";\n"
"import { service2 } from \"../module/2.service\";\n"
"import { service3 } from \"../../module/3.service\";\n"
"import { service4 } from \"../../../module/4.service\";\n"
"import { service5 } from \"../../../../module/5.service\";\n"
"import { service6 } from \"../../../../../module/6.service\";\n"
"import { service7 } from \"../../../../../../module/7.service\";\n"
"import { service8 } from \"../../../../../../../module/8.service\";\n\n"
"import { service9 } from \"@module/9.service\";\n"
"import { service10 } from \"@module/10.service\";\n"
"import { service11 } from \"@module/11.service\";")
subst = "@module"
result = regex.sub(subst, test_str)
if result:
print(result)
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