Regular expression matches Chinese characters and punctuation

Source: Internet
Author: User
Tags xpath

Can be written like this

string @" [\u4e00-\u9fa5]| [\(\)\《\》\——\;\,\。 \ "\" \<\>\! ]";

The first half represents the matching Chinese characters, and the second half is the punctuation that needs to be matched.

Other

For the processing of HTML source code, it is recommended to use Htmlagilitypack, with the following code to remove the script, style or comment content.

 Public StaticHTMLDocument Initializehtmldoc (stringhtmlstring) {    if(string. IsNullOrEmpty (htmlstring)) {return NULL; } HTMLDocument Doc=NewHTMLDocument (); Doc.    Loadhtml (htmlstring); Doc. Documentnode.descendants (). Where (n= = N.name = ="Script"|| N.name = ="style"|| N.name = ="#comment"). ToList (). ForEach (n =N.remove ()); returnDoc;}

Htmlagilitypack is using the XPath syntax, "//comment ()" means "all annotation nodes" in XPath, "#comment" is not good to replace. Http://www.cnblogs.com/rupeng/archive/2012/02/07/2342012.html

Read the Web page content from the URL (static), you can use the following code

 Public Static stringGETHTMLSTR (stringURL) {    if(string. IsNullOrEmpty (URL)) {return string.    Empty; }    stringHTML =string.    Empty; Try{WebRequest WebRequest=webrequest.create (URL); Webrequest.timeout= -* +; using(WebResponse WebResponse =Webrequest.getresponse ()) {            if(((HttpWebResponse) WebResponse). StatusCode = =Httpstatuscode.ok) {stream stream=WebResponse.GetResponseStream (); stringCoder =((HttpWebResponse) WebResponse).                CharacterSet; StreamReader Reader=NewStreamReader (Stream,string. IsNullOrEmpty (coder)?Encoding.Default:Encoding.GetEncoding (coder)); HTML=Reader.            ReadToEnd (); }        }    }    Catch(Exception ex) {//Request may timeout sometimes    }    returnhtml;}

Regular expression matches Chinese characters and punctuation

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.