人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

May 15, 2006

正则表达式使用

Filed under: Regular Expression

—-代码—-

using System.Text.RegularExpressions;

string regexStr = "href\\s*=\\s*\"([^\"]*)\"";
Regex regex = new Regex (regexStr, RegexOptions.IgnoreCase);
MatchCollection matches = regex.Matches(text);

foreach (Match match in matches)
{
    //do sth…
}

—-正则表达式收集—-

//———————————————————–
//形如 href="http://msdn.microsoft.com/netframework/"的连接
//—-注意Group的使用\"([^\"]*)\"
//—-如果使用Groups[1],会返回  http://msdn.microsoft.com/netframework/
//—-如果使用Groups[0],会返回  href="http://msdn.microsoft.com/netframework/"

string regexStr = "href\\s*=\\s*\"([^\"]*)\""
foreach (Match match in matches)
{
    string myURL = match.Groups[1];
}       

Comments »

The URI to TrackBack this entry is: http://recordsome.blogsome.com/2006/05/15/p28/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham