Java Regular Form Summary

Source: Internet
Author: User

Recently used in the form of the expressionBecause recently in the making of an Android news client. The regular form is used for many times. So the summary.

1. Get a picture URL for the content of an article within an RSS feed using the regular formBecause in each news browsing the ListView need the news content in the picture. So you need to crawl the first photo URL address of the article. The photo format for watercress is:

Url=http://img6.douban.com/view/presto/large/public/218991.jpg "/>

You need to get the picture ur address in a multitude of content. This requires a Java statement to write a method
                /** * Extract the src contents of imag in HTML * The returned value is formatted as * http://img6.douban.com/view/presto/large/public/111.jpg */public String getimgstr ( String htmlstr) {string img = "", TMP = ""; Java.util.regex.Pattern p_image;java.util.regex.matcher m_image; String regex_img = "http://[([a-z0-9]|.| /|\\-)]+. [(jpg) | (BMP) | (GIF) | (PNG)] "; /Picture link Address p_image = java.util.regex.Pattern.compile (regex_img, java.util.regex.Pattern.CASE_INSENSITIVE); m_image = P_ Image.matcher (HTMLSTR), while (M_image.find ()) {img = img + "," + M_image.group ();} System.out.println (Img.indexof (",")); if (Img.indexof (",") >= 0) {string[] url=img.substring (1). Split (","); if ( url.length>1) {if (Url[1].indexof ("JPG")!=-1) {return url[1];} Else{return null;}} Else{return null;}} Elsereturn img;}
This method returns the first image URL address. And people will think of the assumption that there is no picture in the article to return NULL, you can also be handsome in the post of the article without pictures. 2. Filter text HyperlinksPresumably everyone in the site, after often use JS with hyperlink greeting. The question I came across was: an article was retrieved from RSS. The text inside contains a super-chain. The fonts that appear on the phone will have color, which can be very ugly. The beginning of the idea is to Baidu search: Android webview eliminate HTML hyperlinks. Get a solution that doesn't allow a browser to use hyperlinks
            Mask Hyperlink    bodyhtml.setwebviewclient (New Webviewclient () {public    Boolean shouldoverrideurlloading (WebView View, String URL) {            return true;        }    });

Click the hyperlink really can't jump to another page, but the font still has color, so I search the direction of the wrong, so searching Java is the form to filter the form of the table to get the results of their own needs, since Baidu is not so smart as everyone thought, Do it yourself as accurately as possible (the first page of the search results actually appeared in PHP, I was drunk)
                Remove hyperlink, keep font string regex= "<\\s*a.*?

/a\\s*> "; Title=title.replaceall (Regex," ");

Of course, you can also remove the hyperlink font can be.


Finally the sentence: just stick to the search, you will be able to find what you need!

!


Java Regular Form Summary

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.