When Word transforms HTML, it leaves a lot of formatting, some formatting is not what we need, however, these formats are more than the actual content of the article, seriously affect the loading speed of the page, so you need to find a good solution to the redundant format to remove. There are many regular expressions on the web that remove the JS version of Word redundancy, only the Java version of the regular expression is available here.
1.public static string Clearwordformat (String content) {2. Convert <P></P> to </div></div> preserve style 3. Content = Content.replaceall ("(<p) ([^>]*>.*?) (<\\/P>) "," <div$2</div> "); 4.//Convert <P></P> to </div></div> and delete style 5. Content = Content.replaceall ("(<p) ([^>]*) (>.*?) (<\\/P>) "," <p$3</p> "); 6.//Remove unwanted label 7. Content = Content.replaceall ("<[/]?" ( Font| font|span| span|xml| xml|del| del|ins| ins|meta| meta| [ovwxpovwxp]:\\w+] [^>]*?> "," "); 8.//Delete the unwanted attribute 9. Content = Content.replaceall ("< (^>]*) (?: Lang| lang|class| class|style| style|size| size|face| face| [ovwxpovwxp]:\\w+] = (?: ' [^ ']* ' |\ "\" [^\ "\"]*\ "\" |[ ^>]+) ([^>]*) > "," <$1$2> "); 10.//Delete the contents of <style type= "Text/css" ></STYLE> and 11. int stylebegin = Content.indexof ("<style"); int styleend = Content.indexof ("</STYLE>") + 8; String style = Content.substring (Stylebegin, StyleenD); Content = Content.replace (style, ""); . return content; 16.}
Remove Word redundant format Java regular expression