# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^.*(?=(?:[^\sA-Z]*[A-Z]){2})"
test_str = ("Unseen ServanTThis creature can be summoned with the spell Unseen Servant.Unseen ServantCreature -1No AlignmentMediumMindlessSource Core Rulebook pg. 380Perception +0; darkvisionLanguages - (understands its creator)Skills Stealth +8Str -4, Dex +2, Con +0, Int -5, Wis +0, Cha +0Invisible An unseen servant is invisible, though it normally doesn’t Sneak, so it is usually only hidden.AC 13, Fort +0, Ref +4, Will +0HP 4; Immunities disease, mental, non-magical attacks, paralysis, poison, precision, unconscious\n"
"; Resistances all damage 5 (except force or ghost touch)Speed fly 30 feetForce Body An unseen servant’s physical body is made of force. It can’t use attack actions. It can move and use Interact actions to do things such as fetch objects, open unstuck or unlocked doors, hold chairs, and clean. It can’t pass through solid objects.\n")
matches = re.search(regex, test_str)
if matches:
print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group()))
for groupNum in range(0, len(matches.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.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