# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"Number\:\s(?<Number>\d+)[\r\n]Category\:\s(?<Category>.*).*[\r\n].*[\r\n].*[\r\n]What\sis\sthe\sspecific\srole\sor\sfunction\sof\sthis\sserver\?\:\s(?<Function>.*).*[\r\n].*[\r\n].*[\r\n].*[\r\n].*[\r\n].*[\r\n].*[\r\n].*[\r\n].*[\r\n].*[\r\n]Server\sHostname\:\s(?<Hostname>.*).*[\r\n]Server\sAllegiance\:\s(?<Domain>.*).*[\r\n].*[\r\n]Physical\sLocation\:\s(?<Location>.*).*[\r\n].*[\r\n].*[\r\n].*[\r\n].*[\r\n]Local\sAdministrators\:\s+([\w\s]+)[\r\n].*[\r\n].*[\r\n]Task\sDescription\:\s(?<Task>.*)"
test_str = ("Task # 12347859 has been opened and assigned to XXXXXXX - . \n"
"Task # 12347859\n"
"Client Details\n"
"Jackie Newman\n"
"servicedesk@thenet.com\n\n"
"Assignment Details\n"
"User course@email.com\n\n"
"Status and Priority Details\n"
"Urgency: 4-LOW\n"
"Impact: 4-MINOR\n"
"Status: Assigned\n"
"Task Details\n"
"Number: 12347859\n"
"Category: Add/Upgrade Server Software \n"
"Application: Production Web Server\n"
"Linked Record: CR123458756 - 2-Implementation\n"
"What is the specific role or function of this server?: XXXXXXXXXX\n"
"What is the primary application for this server deployment?: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
"Provide a detailed description that explains the function or role of the server.: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
"Is this replacing an existing server?: Si\n"
"Please explain when will the old server be decommissioned?: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"
"Is this a physical or virtual server?: XXXXXXXXXX\n"
"What is the required Operating System?: XXXXXXXX YYYYYYYY ZZZZZZZZ\n"
"Patching Schedule: XXX XXX XXX\n"
"Environment - Is the server Production, Development or Disaster Recovery?: XXXXXXXX\n"
"Server Hostname: XXXXXXXX\n"
"Server Allegiance: XXXXXXXX\n"
"Will SQL Server be required on this server?: Non\n"
"Physical Location: CRPNY – Jackieville, Oregon\n"
"Include in Enterprise Backups?: Non\n"
"Resource Requirements: RAM: 8 TB\n"
"Resource Requirements: CPUs: 16\n"
"Resource Requirements: Disk [Quantity and Size(s)]: 2000GB\n"
"Local Administrators: Jackie Newman\n"
"Richard Jackson\n"
"Lewis Asterson\n"
"Kyle Lowry\n"
"Directories to be excluded from Anti-Virus scanning: XXXXX\n"
"Additional Comments:\n"
"Task Description: XXXXXX XXXXXX XXXXXX\n"
"Date and Time Details\n"
"Opened Date: 01/21/2017 3:01 PM Eastern Time")
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