# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(<ptS[a-zA-Z]*Text[a-zA-Z0-9\/=\+\n\t\r\0 \"]+>)([a-zA-Z0-9\/=+\n\t\r\0 &#;\-\.\(\),:£]+)(<\/ptS[a-zA-Z]*Text[a-zA-Z0-9\/=\+\n\t\r\0 \"]*>)"
test_str = ("<CDBText id=\"(0:0-51181)\">\n"
" <dwRefTextOrdner>5622</dwRefTextOrdner>\n"
" <dwRefMitarbeiter>0</dwRefMitarbeiter>\n"
" <ptSName code=\"None\" lang=\"en\">OWN_Text 15</ptSName>\n"
" <dBreite>21</dBreite>\n"
" <dHoehe>29.699999999999999</dHoehe>\n"
" <dOben>2</dOben>\n"
" <dUnten>2</dUnten>\n"
" <dLinks>2</dLinks>\n"
" <dRechts>2</dRechts>\n"
" <cHochQuerformat>0x00</cHochQuerformat>\n"
" <cPapierSchacht>0</cPapierSchacht>\n"
" <cPapierSchachtErsteSeite>0</cPapierSchachtErsteSeite>\n"
" <ptSDruckername code=\"None\" lang=\"en\"></ptSDruckername>\n"
" <ptDErstellungsdatum>Thu 04.Sep 2008</ptDErstellungsdatum>\n"
" <ptDSpeicherungsdatum>Thu 04.Sep 2008</ptDSpeicherungsdatum>\n"
" <ptTSpeicherungszeit>10:10:10 am</ptTSpeicherungszeit>\n"
" <nVersion>3</nVersion>\n"
" <ptSTitel code=\"None\" lang=\"en\"></ptSTitel>\n"
" <ptSThema code=\"None\" lang=\"en\"></ptSThema>\n"
" <ptSAutor code=\"None\" lang=\"en\">ld</ptSAutor>\n"
" <ptSKommentar code=\"None\" lang=\"en\"></ptSKommentar>\n"
" <cGeschuetzt>0x00</cGeschuetzt>\n"
" <cDBTextDaten><xref refid=\"(0:0-51182)\"/></cDBTextDaten>\n"
" </CDBText>\n\n"
" <CDBTextDaten id=\"(0:0-51182)\">\n"
" <ptBKopfzeileText len=\"0\" crc=\"0\">\n\n"
" </ptBKopfzeileText>\n"
" <ptSKopfzeileText code=\"None\" lang=\"en\"></ptSKopfzeileText>\n"
" <ptBKopfzeileFormat len=\"0\" crc=\"0\">\n\n"
" </ptBKopfzeileFormat>\n"
" <ptBFusszeileText len=\"0\" crc=\"0\">\n\n"
" </ptBFusszeileText>\n"
" <ptSFusszeileText code=\"None\" lang=\"en\"></ptSFusszeileText>\n"
" <ptBFusszeileFormat len=\"0\" crc=\"0\">\n\n"
" </ptBFusszeileFormat>\n"
" <ptBMitteText len=\"1031\" crc=\"3139242066\">\n"
"8PHw/1BLAwQUAAAACABFUSQ5KkncyMoCAADTBAAAKwBwAERPQ1VNRX4xL0NBVENM\n"
"SX4xL0xPQ0FMU34xL1RlbXAvMi9ibG8zMC50bXBTRFsApAAAAAAIALXyphxjZGBp\n"
"EGFgYDBggAAfIGZkBTNZRYFE/LvcS4ufyjZ5Wa+KSmHBLcfIxMDAxBDBwAyWlmD4\n"
"zyjPABIDqVUAEgpgtghEnBEiLgSmVCBieOwEAFVUDQAH8qW/SPKlv0jypb9IbVPd\n"
"TtswFO7dtEp9h3MJoi0dGruAq6pkUIlS1HYgLt3kJDF17M52ChGPw4vus1MG+6kU\n"
"p3KOfb6/M5nfLJObFX2fL2bU6xKeT/j9uYZ3r3vP5Lw1ulANWU5NVbHOyJfCk1CK\n"
"tuwdCctUbwfeDDLhmZ6kL2kn0lRq4aXRjtacG9SIrJLOYWfY694qFg5bbkMyp8bU\n"
"7S3a1Xg9lexLtmHbUmYKMpZSdJSO8loBydYaz6nnDDcB/CK5Tu7GIDRLLqaT8TVd\n"
"TZer+eKByDFH2DZzRAeFcQDiy8PADuduF/NJcvFjkdAla7ZCkdCCHXp7mfbJpUIB\n"
"IvhujZKupCPiZ29FGliRyYnW1mxYkzfGl306Oh6guiETwb+Xutis1fPt6XWnVMgd\n"
"UwU2bPfCEOBBXDRdG3wDzZSzoEgAUeuMrfPio/6uTsv3MgeVrG1IkKvCV1YMu3yA\n"
"aqXbDEPTv2+ZWJN7ugs+1jAkNF9DAjJbaSSYC6kpNRoZgDo7IZVY70XBrgu3exNP\n"
"hdNo5Eu45ETe1nCew6fAs6wroSmzdUG4MbL2w2ErSyvIPf83YcgQurgWeGGkLqgS\n"
"j9AJUSnYNn1it+VUihAMo1AUU9kvBboKWitjcF2g9Fhj+ZBFLRFt8WamoOLfEAxb\n"
"pzJDx2HRxgPjz1qGG6A7DwzME5Fg28illrn1seVIy2iF0BJvRwd7PpRLxYdnN6Li\n"
"8y+jb6ej/To6/3qOuHzudceXiySZhTFdzel2/NDrJsvVdDZeJWdEryejEQ3o5OQ0\n"
"AoyjEYYlBDVtgiUIxU5mTKlq5YtTCQcwl7UNY5pjNEATsDyD5pV54h3bfvQSfxrC\n"
"9IbohZzv2LPFOGO34kxislt79xbAkA3CJwGj2hokOUQkYgjFHklxQMDPGAfVxBSK\n"
"AjLFEtFEm4EGDELUlOLfA7aPSZuRfUyWstCcnb3lptN56Ww6L78AUEsBAhcLFAAA\n"
"AAgARVEkOSpJ3MjKAgAA0wQAACsAEQAAAAAAAAAgALaBAAAAAERPQ1VNRX4xL0NB\n"
"VENMSX4xL0xPQ0FMU34xL1RlbXAvMi9ibG8zMC50bXBTRAQApAAAAFVUBQAH8qW/\n"
"SFBLBQYAAAAAAQABAGoAAACDAwAAAAA=\n"
" </ptBMitteText>\n"
" <ptSMitteText code=\"None\" lang=\"en\">CONSENT FORM \n"
" \n"
"\n"
"\n"
"\n"
"\n"
"\n"
"We strongly recommend that all pets are up-to-date with vaccinations before admission.\n"
"Please ask if you are unsure whether your dog or cat is fully protected.\n"
" \n"
"RELEVANT MEDICAL HISTORY see records (gosforth)\n"
"\n"
" \n"
"PROCEDURE General anaesthetic, scale and polish + extraction of broken tooth, +/- any other extractions\n"
" \n"
"\n"
"\n"
"\n"
"\n"
"\n"
"I give my permission for the above procedure and understand that all such procedures carry a small element of risk.\n"
"I understand that Croft Vets use the best opioid pain control available and consent to the use of this safe and effective human drug in my pet..\n"
"\n"
"\n"
"\n"
"We recommend that all patients undergoing major surgery, especially older pets,have a blood test just before administration of a general anaesthetic.\n"
"\n"
"I do / do not require a pre-operative blood screen for my pet Small animals (patient file):Name;10650;10650;0;4;\n"
" \n"
"AGREEMENT TO PAY\n"
"ESTIMATE: £200 - 225\n"
"\n"
"It is our policy to provide clients with an accurate fee estimate.\n"
"However, the very nature of veterinary medicine and surgery makes it impossible to predict costs exactly.\n"
"I agree to pay all fees on collection of my pet.\n"
"\n"
"\n"
"Signed:\n"
"\n"
"</ptSMitteText>\n"
" <ptBMitteFormat len=\"3251\" crc=\"1808381608\">\n"
"8PHw/1BLAwQUAAAACABFUSQ5oClCBnYLAADi2AAAKwBwAERPQ1VNRX4xL0NBVENM\n"
"SX4xL0xPQ0FMU34xL1RlbXAvMi9ibG8zMi50bXBTRFsApAAAAAAIALXyphxjZGBp\n"
"EGFgYDBggAAfIGZkBTNZRYFE/LvcS4ufyjZ5Wa+KSmHBLcfIxMDAxBDBwAyWlmD4\n"
"zyjPABIDqVUAEgpgtghEnBEiLgSmVCBieOwEAFVUDQAH8qW/SPKlv0jypb9I7Z1t\n"
"bFPXGcef67w4kGDyWigwdLclDVAgdgghYFCXF0MCxPFigwfTNJzklhjyArG7JkVd\n"
"sqoKrVStUVWh7kNbTxVSPmzSmKjEuk6DghhFCBDSNqQhTXwaK5rGh6mbKrq759xr\n"
"c+17bcfOPcaJ9jzm75fjc849vjnc3/Occ3xcMLkBAEQoxvuNwkbhtvW2dbBtYOBB\n"
"gQ3WwZ9lUGxGYPeFAJW+4LAUEt3Sy2Lv6HBgBAyWpJDYOhYMDEFGhT61gJDZkQrs\n"
"cNNMoVjzBEOhI8LG53fD7+8eEa5+eHP/Jx/DWrg/Z6FN8N+P33115tIlJYelMPEz\n"
"ZVhI0I6URaGEE5FpIRH+mn2h+M8kZNgjimrhL9kfSSukWkanPP5IGTfvTPQJlpRl\n"
"9UG5RV+yO5jEf5Pqg3KLvsS7ixcvghyJgHwT9XUEbskRiCi6hZIhcgsVkeEWSo58\n"
"jboJst8P8puoK6j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Vyd3ejWnsI8kCjRLigNf9fwhYrkDY7NaT0uyNOvqLYHQoMpobmsmKBJ0CRoEjQJ\n"
"movhV1RvK+ypX5nIHkHHGv3jI8g7NB8oDT+Zgvb6hR+xxxWWvDccilnDX83QTYl9\n"
"kC/z4aaw38o9GAwFGlr7+6VQKOWiyqtWgj5Bn6BP0Cfom4G+OiMV26GA/epA4uiv\n"
"hozcLKpU14ecWJWdM/AQ8s5UXtMbkGy4fV51G2u3Gurm802PI4o/Ub8mX0P5/86H\n"
"Z8IOyNYApR69/wP5JOSTkE9CPgmQT8JrA2Clq+VoIGJcwdgeA8bSw+fO8jzAh8Pa\n"
"1H+sIjoRnYhORCeiE9+1qbE9/RilYmtTNVOf84yeY/ub44VLIdi6Ob6SqH/cVpSn\n"
"gd32Qan/uDQg9k2kDqJaSghThCnCFGGKMMVrYJdZaU43sqvO8lvxTWWLdAA3menX\n"
"vv8PUEsBAhcLFAAAAAgARVEkOaApQgZ2CwAA4tgAACsAEQAAAAAAAAAgALaBAAAA\n"
"AERPQ1VNRX4xL0NBVENMSX4xL0xPQ0FMU34xL1RlbXAvMi9ibG8zMi50bXBTRAQA\n"
"pAAAAFVUBQAH8qW/SFBLBQYAAAAAAQABAGoAAAAvDAAAAAA=\n"
" </ptBMitteFormat>\n"
" </CDBTextDaten>\n")
matches = re.finditer(regex, test_str, re.DOTALL | 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