# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"<pre>(?<line>\d+\..+)<\/pre>"
test_str = ("table>\n"
" <tr>\n"
" <td>\n"
" <pre>1. APEAL/890/2010 HUSSAIN ISMAIL SATWILKAR SHRI C.K. PENDSE</pre>\n"
" </td>\n"
" </tr>\n"
" <tr>\n"
" <td>\n"
" <pre> [Criminal] MS.ROHINI DANDEKAR ADV.AP</pre>\n"
" </td>\n"
" </tr>\n"
" <tr>\n"
" <td>\n"
" <pre> V/S THE STATE OF MAHARASH PTD AS PER CTS ORD 7/9/17</pre>\n"
" </td>\n"
" </tr>\n"
" <tr>\n"
" <td>\n"
" <pre> TRA P.P.FOR P. P</pre>\n"
" </td>\n"
" </tr>\n"
" <tr>\n"
" <td>\n"
" <pre></pre>\n"
" </td>\n"
" </tr>\n"
" <tr>\n"
" <td>\n"
" <pre> REMARK : (By Accused against Conviction) Note: (1) Matter is Ready for final</pre>\n"
" </td>\n"
" </tr>\n"
" <tr>\n"
" <td>\n"
" <pre> hearing. (2) Accd. is in jail. (3) R & P with PB received. (4)</pre>\n"
" </td>\n"
" </tr>\n"
" <tr>\n"
" <td>\n"
" <pre> Muddemal article are to be called for. (5) Report received from</pre>\n"
" </td>\n"
" </tr>\n"
" <tr>\n"
" <td>\n"
" <pre> Nashik Central Prison stated therein that \"Orig. accd. death dated</pre>\n"
" </td>\n"
" </tr>\n"
" <tr>\n"
" <td>\n"
" <pre> 20/11/2015 (Report kept at flag \"A\") . ....... Court (DB) for final</pre>\n"
" </td>\n"
" </tr>\n"
" <tr>\n"
" <td>\n"
" <pre> hearing.</pre>\n"
" </td>\n"
" </tr>\n"
" <tr>\n"
" <td>\n"
" <pre></pre>\n"
" </td>\n"
" </tr>\n"
" <tr>\n"
" <td>\n"
" <pre></pre>\n"
" </td>\n"
" </tr>\n"
" <tr>\n"
" <td>\n"
" <pre></pre>\n"
" </td>\n"
" </tr>\n"
" <tr>\n"
" <td>\n"
" <pre>2. APEAL/966/2011 ABDUL MALIK SHAIKH SHRI S. R. MITHARE</pre>\n"
" </td>\n"
" </tr>\n"
" <tr>\n"
" <td>\n"
" <pre> [Criminal]</pre>\n"
" </td>\n"
" </tr>\n"
" <tr>\n"
" <td>\n"
" <pre> V/S THE STATE OF MAHARASH</pre>\n"
" </td>\n"
" </tr>\n"
" <tr>")
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