# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?<![\u4E00-\u9FAF\u3040-\u3096\u30A1-\u30FA\uFF66-\uFF9D\u31F0-\u31FF])(?<!\d)(?<!\d\.)(\d+(?:\.\d+)?m2)"
test_str = ("\"110.94m2・129.24m2\";\n"
" --> 110.94m2 and 129.24m2\n"
"\"81.95m2(24.78坪)、うち2階車庫8.9m2\" \n"
" --> 81.95m2\n"
"\"80.93m2(登記)\"\n"
" --> 80.93m2\n"
"\"93.42m2・93.85m2(登記)\"\n"
" --> 93.42m2 and 93.85m2\n"
"\"81.82m2(実測)\"\n"
" --> 81.82m2\n"
"\"81.82m2(実測)、うち1階車庫7.82m2\"\n"
" --> 81.82m2\n"
"\"90.11m2(実測)、うち1階車庫8.07m2\"\n"
" --> 90.11m2")
matches = re.finditer(regex, test_str, re.MULTILINE)
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