Remove Word redundant format Java regular expression

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.