# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"\[serviceOrderId:(?<oc_request_id>.[^]]*)\]"
test_str = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"><html><head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body><div><font face=\"Arial\" color=\"#000000\" size=\"2\">***** Reply to this email to append information to [[WO#17561]] *****<br><br>WO# 17561 was amended to include the following information:<br><br>Thank you for contacting us.<br><br><br>We have received your request and will respond within 2 business days.<br><br><br>Your request number is: REQ-20665.<br><br><br>If you would like to speak with a representative, please contact us at 1 855 242-4492 and reference your request number.<br><br><br>Our hours of operation are Monday to Friday, 8:00 am to 5:00 pm AST.<br><br><br>Thank you for your continued business with Bell Aliant.<br><br><br>Client Services<br>Bell Business Markets<br><br><br><br><br><br><br><br>Legal | Privacy | bell.ca <br><br>Corporate Secretary’s Office of Bell Canada, Bell TV, Bell Mobility, Bell Media and Bell Aliant<br>1 carrefour Alexander-Graham-Bell, Building A-7, Verdun, Quebec, H3E 3B3 <br><br><br><br>© Bell Canada, 2020. All rights reserved.<br><br><br><br><br>[serviceOrderId:bsd_REQ-20665] <br><br>Merci de nous avoir contacté.<br><br><br>Nous avons bien reçu votre demande et nous y réponderons dans 2 jours ouvrables.<br><br><br>Votre numéro de demande est : REQ-20665.<br><br><br>Si vous souhaitez parler à un conseiller, veuillez composer le 1 855 242-4492 et faire référence à votre numéro de demande.<br><br><br>Nos heures d'ouverture sont de 8 h à 17 h AST, du lundi au vendredi.<br><br><br>Merci de votre fidélité envers Bell Aliant.<br><br><br>Services clients<br>Bell Marché Affaires<br><br><br><br><br><br><br><br>Avis juridiques | Sécurité | bell.ca <br><br>Bureau du secrétaire de Bell Canada, Bell Télé, Bell Mobilité, Bell Média et Bell Aliant<br>1, carrefour Alexander-Graham-Bell, Aile A-7, Verdun (Québec) H3E 3B3 <br><br><br><br>© Bell Canada, 2020. Tous droits réservés.<br><br><br><br><br>[serviceOrderId:bsd_REQ-20665]<br><br></font></div><hr> <span style=\"font-size: 12px;\"><font color=\"blue\"><em><strong>External Email:</strong> Please use caution when opening links and attachments / </em></font></span><em> <span style=\"font-size: 12px;\"><font color=\"blue\"><strong>Courriel externe:</strong> Soyez prudent avec les liens et documents joints </font></span></em></body></html>"
matches = re.search(regex, test_str, re.IGNORECASE)
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