import re
regex = re.compile(r"^[^-]*$", flags=re.MULTILINE)
test_str = ("Believing neglected so so allowance existence departure in.\n"
"In design active temper be uneasy. Thirty for remove plenty \n"
"regard you summer though. He preference connection astonished \n"
"on of yet. ------ Partiality on or continuing in particular principles as. \n"
"Do believing oh disposing to supported allowance we.\n"
"-------\n"
"Admiration we surrounded possession frequently he. \n"
"Remarkably did increasing occasional too its difficulty \n"
"far especially. Known tiled but sorry joy balls. Bed sudden \n\n"
"manner indeed fat now feebly. Face do with in need of \n"
"wife paid that be. No me applauded or favourite dashwoods therefore up\n"
"distrusts explained. \n"
"----t--\n"
"------\n"
"And produce say the ten moments parties. Simple innate summer \n"
"fat appear basket his desire joy. Outward clothes promise at gravity \n"
"do excited. \n"
"Sufficient particular impossible by reasonable oh expression is. Yet \n"
"preference \n"
"connection unpleasant yet melancholy but end appearance. And \n"
"excellence partiality \n"
"estimating terminated day everything. \n"
"--------- ")
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