# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?:©(?:\s*Copyright)?|Copyright(?:\s*©)?)\s*\d+(?:\s*-\s*\d+)?\s*(.*?(?=\W*All\s+rights\s+reserved)|[^.\n]*(?=\.)|.*)"
test_str = ("Copyright © 2019 Apple Inc All rights reserved.\n"
"© 2019 Quid, Inc. All Rights Reserved.\n"
"© 2009 Database Designs \n"
"© 2019 Rediker Software, All Rights Reserved\n"
"©2019 EVOSUS, INC. ALL RIGHTS RESERVED\n"
"© 2019 Walmart. All Rights Reserved.\n"
"© Copyright 2003-2019 Exxon Mobil Corporation. All Rights Reserved.\n"
"Copyright © 1978-2019 Berkshire Hathaway Inc.\n"
"© 2019 McKesson Corporation\n"
"© 2019 UnitedHealth Group. All rights reserved.\n"
"© Copyright 1999 - 2019 CVS Health\n"
"Copyright 2019 General Motors. All Rights Reserved.\n"
"© 2019 Ford Motor Company\n"
"©2019 AT&T Intellectual Property. All rights reserved.\n"
"© 2019 GENERAL ELECTRIC\n"
"Copyright ©2019 AmerisourceBergen Corporation. All Rights Reserved.\n"
"© 2019 Verizon\n"
"© 2019 Fannie Mae\n"
"Copyright © 2018 Jonas Construction Software Inc. All rights reserved.\n"
"All Comments © Copyright 2017 Kroger | The Kroger Co. All Rights Reserved\n"
"© 2019 Express Scripts Holding Company. All Rights Reserved. 1 Express Way, St. Louis, MO 63121\n"
"© 2019 JPMorgan Chase & Co.\n"
"Copyright © 1995 - 2018 Boeing. All Rights Reserved.\n"
"© 2019 Bank of America Corporation. All rights reserved.\n"
"© 1999 - 2019 Wells Fargo. All rights reserved. NMLSR ID 399801\n"
"©2019 Cardinal Health. All rights reserved.\n"
"© 2019 Quid, Inc All Rights Reserved.")
matches = re.finditer(regex, test_str, re.MULTILINE | re.IGNORECASE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# 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