# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)(?=')"
test_str = ("(SU 08624476) Shrewton 5b; Mutilated, diameter approx. 20 paces, height approx 3'. (1)\n\n"
"SU 08624475: Shrewton 5b; site only, diameter 22m, plotted from AP at 1:2500 (2,3)\n\n"
"Barrow, no recorded excavations taken place. (4)\n\n"
"The cropmark remains of the Bronze Age bowl barrow described by the previous authorities were seen as a ring ditch with a diameter of 30m centred at SU 0862 4475. It was mapped at 1:10,000 scale as part of the RCHME: Salisbury Plain Training Area NMP Project, and subsequently revised for the English Heritage Stonehenge WHS Mapping Project. This barrow was recorded collectively with four other barrows in NMR record SU04SE 31 as a barrow cemetery. Eight further barrows from the eastern end of the same cemetery lie immediately to the south of the modern road. These have been recorded separately in NMR record SU04SE 26. (5)\n"
"1\n"
"VIRTUAL CATALOGUE ENTRY TO SUPPORT NAR MIGRATION\n"
"VCH Wilts 1, 1957, 190 (L.V Grinsell)\n\n\n"
"2\n"
"Aerial photograph\n"
"AP (Crawford Collection 1097, undated)\n\n\n"
"3\n"
"Field Investigators Comments\n"
"F1 PAS 21-Nov-1974\n\n\n"
"4\n"
"VIRTUAL CATALOGUE ENTRY TO SUPPORT NAR MIGRATION\n"
"Proc. Prehistoric Soc. 50, 1984, 257 (C. Green, S. Rollo-Smith)\n\n\n"
"5\n"
"VIRTUAL CATALOGUE ENTRY TO SUPPORT NAR MIGRATION\n"
"NMR OS/70067 218 03-MAY-1970\n\n\n\n"
"1\n"
"VIRTUAL CATALOGUE ENTRY TO SUPPORT NAR MIGRATION\n"
"VCH Wilts 1, 1957, 190 (L.V Grinsell)\n\n\n"
"2\n"
"Aerial photograph\n"
"AP (Crawford Collection 1097, undated)\n\n\n"
"3\n"
"Field Investigators Comments\n"
"F1 PAS 21-Nov-1974\n\n\n"
"4\n"
"VIRTUAL CATALOGUE ENTRY TO SUPPORT NAR MIGRATION\n"
"Proc. Prehistoric Soc. 50, 1984, 257 (C. Green, S. Rollo-Smith)\n\n\n"
"5\n"
"VIRTUAL CATALOGUE ENTRY TO SUPPORT NAR MIGRATION\n"
"NMR OS/70067 218 03-MAY-1970\n\n")
matches = re.finditer(regex, test_str)
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