比如:
asdfafsa1234567
werfsfsd1234567dfg

解决方案 »

  1.   

    ^[\s\S]*\d{7}[\s\S]*$
    ^[\w\W]*\d{7}[\w\W]*$
    ^[\d\D]*\d{7}[\d\D]*$ 
      

  2.   


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;namespace ConsoleApplication14
    {
        class Program
        {
            static void Main(string[] args)
            {
                string str = "werfsfsd1234567dfg";
               str= Regex.Replace(str, @"[a-z]", "");
                Console.WriteLine(str);
                Console.ReadKey();
            }
        }
    }
      

  3.   

    Regex objRegex = new Regex(@"(?<=\D|^)(?:(?:9(?=8|\D))?(?:8(?=7|\D))?(?:7(?=6|\D))?(?:6(?=5|\D))?(?:5(?=4|\D))?(?:4(?=3|\D))?(?:3(?=2|\D))?(?:2(?=1|\D))?(?:1(?=0|\D))?(?:0(?=\D|$))?)(?=\D|$)");            
    MatchCollection objMatches = objRegex.Matches(str);
      

  4.   

    提取的话,这样就行了            Regex reg = new Regex(@"\d{7}");
                MatchCollection mc = reg.Matches(yourStr);
                foreach (Match m in mc)
                {
                    richTextBox2.Text += m.Value + "\n";
                }