# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(>\\\${}((.*))<)"
test_str = ("<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://www.neustar.biz/clearinghouse/SOAPRequestHandler/1.0\">\n"
" <soapenv:Header/>\n"
" <soapenv:Body>\n"
" <ns:processSync soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n"
" <in0 xs:type=\"type:string\" xmlns:xs=\"http://www.w3.org/2000/XMLSchema-instance\"><![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\"?><header>\n"
" <Request value=\"SOARequest\"/>\n"
" <Subrequest value=\"SvCreateRequest\"/>\n"
" <CustomerIdentifier value=\"PAT_TST\"/>\n"
" <Supplier value=\"NEUSTAR\"/>\n"
" <InterfaceVersion value=\"1_0\"/>\n"
" <UserIdentifier value=\"example\"/>\n"
" <UserPassword value=\"example\"/>\n"
" <ApplyBusinessRules value=\"Y\"/>\n"
" <Action value=\"submit\"/>\n"
"</header>]]></in0>\n"
" <in1 xs:type=\"type:string\" xmlns:xs=\"http://www.w3.org/2000/XMLSchema-instance\"><![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAMessage>\n"
" <UpstreamToSOA>\n"
" <UpstreamToSOAHeader>\n"
" <InitSPID value=\"XS11\"/>\n"
" <OID value=\"242424249\"/>\n"
" <DateSent value=\"06-19-2017-080000AM\"/>\n"
" <SvType value= \"Wireline\"/>\n"
" <Action value=\"submit\"/>\n"
" </UpstreamToSOAHeader>\n"
" <UpstreamToSOABody>\n"
" <SvCreateRequest>\n"
" <Subscription> \n"
" <Tn value=${Tn}/>\n"
" </Subscription>\n"
" <LnpType value=\"lspp\"/>\n"
" <Lrn value=\"4444787878\"/> \n"
" <NewSP value=\"XS11\"/>\n"
" <AccountId value=\"09040820157163815095\"/>\n"
" <AccountName value=\"HIMANSHUTHKNMUAWVF\"/>\n"
" <OldSP value=\"XS22\"/>\n"
" <SvType value=\"Wireline\"/>\n"
" <MMSURI value=\"-\"/> \n"
" <NewSPDueDate value=\"11-29-2017-1100PM\"/>\n"
" <PortToOriginal value=\"0\"/>\n"
" </SvCreateRequest>\n"
" </UpstreamToSOABody>\n"
" </UpstreamToSOA>\n"
"</SOAMessage>]]></in1>\n"
" </ns:processSync>\n"
" </soapenv:Body>\n"
"</soapenv:Envelope>")
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