日期:2014-05-20  浏览次数:20645 次

正则表达式截取指定开头和结尾的字符串
String testStr="<SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/>"
  +"<SOAP-ENV:Body>"
  +"<samlp:ArtifactResolve xmlns:samlp=urn:oasis:names:tc:SAML:2.0:protocol xmlns:saml=urn:oasis:names:tc:SAML:2.0:assertion ID=id_2 Version=2.0 IssueInstant=2007-12-05T09:22:04Z>"
  +"<saml:Issuer>https://idm.10086.cn/SSO</saml:Issuer>"
+"<samlp:Artifact>e4fd0055e1e64077aadf39c98a2814a2</samlp:Artifact>"
  +"</samlp:ArtifactResolve>"
  +"</SOAP-ENV:Body>"
+"</SOAP-ENV:Envelope>";
截取<SOAP-ENV:Body>和</SOAP-ENV:Body>标签之间的内容,用java的正则表达式实现

在线等求解,急急急!


------解决方案--------------------
for example
Java code
testStr = testStr.replaceAll("(?is).*?<SOAP-ENV:Body>(.*?)</SOAP-ENV:Body>.*", "$1");
System.out.println(testStr);