我在android平台上工作,我使用一个字符串变量来填充html内容,之后我想删除一些单词(具体来说-删除之间的任何单词)<head>..</head>
标签。有什么解决办法吗?
String newHtml = oldHtml.replaceFirst("(?s)(<head>)(.*?)(</head>)","$1$3");
解释:
oldHtml.replaceFirst(" // we want to match only one occurrance
(?s) // we need to turn Pattern.DOTALL mode on
// (. matches everything, including line breaks)
(<head>) // match the start tag and store it in group $1
(.*?) // put contents in group $2, .*? will match non-greedy,
// i.e. select the shortest possible match
(</head>) // match the end tag and store it in group $3
","$1$3"); // replace with contents of group $1 and $3
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)