String newHtml = oldHtml.replaceFirst("(?s)(
)(.*?)()","$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)
(
) // 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
() // match the end tag and store it in group $3
","$1$3"); // replace with contents of group $1 and $3