import re
regex = re.compile(r"\/\/==start==\n(.+\n)*\/\/==end==")
test_str = ("var originalString = `// @Author: someone\n"
"// @Date: 2018-01-23T16:46:09-04:00\n"
"// @Email: dddddddd@gmail.com\n"
"// @Filename: _material.themes.scss\n"
"// @Last modified by: Someone\n"
"// @Last modified time: 2018-01-23T18:40:39-04:00\n\n"
"@include angular-material-theme($theme);\n\n"
".app-dark {\n"
" @include angular-material-theme($dark-theme);\n"
"}\n\n"
".app-pink {\n"
" @include angular-material-theme($pink-theme);\n"
"}\n\n"
"//==start==\n"
"//==end==`")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
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