jjccx

jjccx's blog
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

正则表达式日积月累

Posted on 2004-12-10 22:53  jjccx  阅读(983)  评论(11)    收藏  举报

连接1:正则表达式语言元素

正则表达式的使用: 

    Regex r;

    Match m;

    r = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);

    for(m = r.Match(input); m.Success; m = m.NextMatch())

    {
        System.Console.WriteLine(m.ToString());

    }

    //Replace:dest = System.Text.RegularExpressions.Regex.Replace(src, pattern, replacement, RegexOptions.Multiline);
    //Match:System.Text.RegularExpressions.Regex.Match("in", "i", System.Text.RegularExpressions.RegexOptions.Multiline).Success
//===============================================================================================//
//===============================================================================================//
1. 在C#中,怎么用正则表达式匹配出没有被注释的中文?
    如:  

    //这是被注释的中文

    //"这也是被注释的中文"

    #region 这是被注释的中文

    #endregion


    #region
"这都是被注释的中文"

    #endregion "这都是被注释的中文"


    string
str="这是没有被注释的中文";

    this.cmdDel.Attributes.Add("onClick","return IsCheckBoxChecked('这是被注释的中文吗?','不是!')");

    string str="这是没有被注释的中文";

    //this.cmdDel.Attributes.Add("onClick","return IsCheckBoxChecked('这是被注释的中文吗?','是的!')");

    解答:(?<=//.*|#region.*)(?<data>[\u4e00-\u9fa5]+)|(?<=/\*[\W\w]*)(?<data>[\u4e00-\u9fa5\r\n]+)(?=[\W\w]*\*/)
2.