高分求1正则  
在一串字符串中取最后一次出现  XXX-XXXXXXXXXX格式的字符串,X为数字 并且在这个字符之后20个字符内无 "VOID" 字符串 谢谢大家 帮帮忙啦

解决方案 »

  1.   

    string result = Regex.Match(yourStr,@"(?s)\d{3}-\d{10}(?=((?!void).){0,20}((?!\d{3}-\d{10}).)*$)").Value;
      

  2.   

    //void我是小写的,如果你一定要大写,这样
    string result = Regex.Match(yourStr,@"(?s)\d{3}-\d{10}(?=((?!VOID).){0,20}((?!\d{3}-\d{10}).)*$)").Value;//如果你不限制大小写string result = Regex.Match(yourStr,@"(?is)\d{3}-\d{10}(?=((?!void).){0,20}((?!\d{3}-\d{10}).)*$)").Value;
      

  3.   

    貌似在这个字符之后20个字符内无 "VOID" 这个条件没匹配上啊  谢谢啦
      

  4.   

    疏忽了。
    换一下string result = Regex.Match(yourStr,@"(?is)\d{3}-\d{10}(?=(((?!void).){20}|((?!void).){0,19}$)((?!\d{3}-\d{10}).)*$)").Value;再试试
      

  5.   


                string str = @"123-1234567890  098-0987654321 void";            Regex reg = new Regex(@"(?(?=\d{3}-\d{10}.{0,16}void)|\d{3}-\d{10})");            MatchCollection matches = reg.Matches(str);
                if (matches.Count == 0 || matches[matches.Count - 1].Value == "")
                    Console.WriteLine("No Match");
                else
                    Console.WriteLine(matches[matches.Count - 1].Value);
      

  6.   

    try
    string result = Regex.Match(yourStr,@"(?is)\d{3}-\d{10}(?=(((?!void).){20}|((?!void).){0,19}$))",RegexOptions.RightToLeft).Value;
      

  7.   


                string str = @"123-1234567890  098-0987654321 void";            Regex reg = new Regex(@"(?i)(?(?=\d{3}-\d{10}.{0,16}void)|\d{3}-\d{10})");            MatchCollection matches = reg.Matches(str);
                for (int i = matches.Count - 1; i >= 0; i--)
                {
                    if (matches[i].Value != "")
                    {
                        Console.WriteLine(matches[i].Value);
                        break;
                    }
                }