# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"[0-9]*.?"
test_str = ("393. A gypsy caravan passes. They might have interesting items for sale or trade, but \n"
"they have touchy tempers and strange customs. They might even want to capture a \n"
"PC or pet to sell in the next town. \n"
"394. A thief tries to infiltrate the party to steal from them. \n"
"395. A fallen tree blocks the road ahead. You notice a path going around it but cannot \n"
"see the other side. \n"
"396. An nearby tree is infested with animated objects that attack travelers that disturb \n"
"their swarm. \n"
"3979. A press gang accosts travelers just down the road. \n"
"398. A mounted patrol of soldiers ask travellers what they have seen, then pass on the \n"
"King's warning to be law-abiding. \n"
"399. An otherwise empty stretch of highway, with two rival taverns facing each other \n"
"across the road. The publicans try to outdo each other loudly on the discounts and \n"
"benefits of their respective establishments to the party. Both seem desperate for \n"
"customers. ")
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