string s = "百位邻期方案23";要求:
如果字符串s中具有“方案”二字,就取“方案”以前的字符串。
如果没有“方案”二字,就全取字符串s。
正则表达式该怎么写?

解决方案 »

  1.   

    本帖最后由 bdmh 于 2012-05-28 13:57:39 编辑
      

  2.   


    new Regex("(?is)((.*方案)|(.*))")
      

  3.   

    string s = "百位邻期方案23";
                string regx = "(.*)方案|(.*)";
                Match one = Regex.Match(s, regx);
                Console.WriteLine(one.Groups[1].Value == "" ? one.Groups[2].Value : one.Groups[1].Value);