如上题 ,下面给出字符串
Please contact us for more information about this product.  Our    fax number is 1-800-123-4567  Or call us is 1-800-765-4321,    or pager number is 1-800-777-1111  Our alternate fax number,     which is only available during business hours, is 1-000-111-2222
我想获取fax后的传真号,如1-800-123-4567 1-000-111-2222而不是 call后的, 如1-800-765-4321,1-000-111-2222主要问题是如何跳过字符查找,
说明:字符串只是作为参考,不一定就只有取2个字符串要提取,是未知的,不要通过对fax后到传真号多少字符来来判断

解决方案 »

  1.   

    http://www.cnblogs.com/time-is-life/articles/368186.html
      

  2.   

    /fax number is \d-\d{3}-\d{3}-\d{4}/
      

  3.   

    Regex r = new Regex("fax number is \d-\d{3}-\d{3}-\d{4}"); 
    Match m = r.Match("你的字符串");
    if(m.Success)
    {
        string str = "你的字符串".substring(m.index, "fax number is 0-000-000-0000".length);
       你要的传真号 = str.remove(0,"fax number is ".length);
    }
      

  4.   

    yusongkun(九道轮回) 不要算长度啊 ,你们还真会钻,不要算后的,你们就算前面的
      

  5.   

    看这是不是你要的结果string yourStr = ...............;
    MatchCollection mc = Regex.Matches(yourStr, @"fax[\s\S]*?(?<fax>(\d+-)+\d+)", RegexOptions.IgnoreCase);
    foreach(Match m in mc)
    {
        richTextBox2.Text += m.Groups["fax"].Value + "\n";
    }
      

  6.   

    string str = @"fax\snumber\sis\s(?<Fax>[\d-]+)\sOr";凑个热闹我取的FAX 是数字和-  所以没位数
      

  7.   

    static void Main(string[] args)
    {
    Regex r = new Regex("fax number is (?<faxnumber>\\d-\\d{3}-\\d{3}-\\d{4})");
    Match m = r.Match("Please contact us for more information about this product.Our fax number is 1-800-123-4567  Or call us is 1-800-765-4321");
    Console.WriteLine("faxnumber" + "------" + m.Groups["faxnumber"].Value);
    Console.Read();
    }
    刚刚找到的方法,很不错
      

  8.   

    你说的意思我不太清楚,字符串格式不固定吗?
    是不是要提取 fax number 后面第一次出现的号码?
      

  9.   

    number前面跟上你的文字描述不就好了么,如 the fax number is; the call number is
      

  10.   

    string str = @"fax\snumber\sis\s(?<Fax>[\d-]+)\sOr";凑个热闹我取的FAX 是数字和-  所以没位数---------------------你这样写肯定是有问题的,难度你的传真号可以是这样的格式? 112-1-12-11111-111111