Regular Expression [prototype] of the weather forecast (WW. yesur. com)

Source: Internet
Author: User

// Test RegEx
String content = "";
String outhtml = "";
RegEx;
Match MC;
Streamreader sr = new streamreader ("C: // a.txt", system. Text. encoding. getencoding ("gb2312 "));
Content = Sr. readtoend ();
Content = content. Replace ("/"","'");

// Start to use the regular expression to retrieve the image file name

// RegEx = new RegEx ("class =/" text02/"> (? <Cityname>. *) </div> ");
RegEx = new RegEx (@ "(/S *) <TD width = '000000' bgcolor = 'f6f6f6 'class = 'text02'> (/S *)(? <Cityname>. *) (/S *) </TD> (/S *) <TD width = '55' align = 'center' bgcolor = 'f6f6f6 '> (/S *) (? <Weather>. *) (/S *) </TD> ", regexoptions. Compiled );

Outhtml + = "<Table widht = 100% border = 1 bgcolor = d7d7d7> ";
Outhtml + = "<tr> <TD colspan = 10> test </TD> </tr> ";
For (MC = RegEx. Match (content); Mc. success; MC = mc. nextmatch ())
{
Outhtml + = "<tr> <TD> City: </TD> <TD>" + MC. groups ["cityname"]. value + "</TD> <TD>" + MC. groups ["Weather"]. value + "</D> </tr> ";
}
Outhtml + = "</table> ";

Response. Write (outhtml );

 

*******************************

One of the key points is:

<Tr> <TD> must be expressed by (/S *). This indicates an infinite number of spaces. Otherwise, cool

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.