1、提取一字符串中的所有数字;
2、判断提取后的数字长度,是否大于9。如大于9位,则截取;如小于9位,在前面用0补齐;(9是用程序参数控制,并不一定真正是9位数字)
3、在截取处理后的数字前面加上一个字定的数字,如00101;(从程序参数传递)
根据上面三点要求,求一正则表达式,在等等,急用呀

解决方案 »

  1.   


    String str = "ufosjf9e79u43j4t908475t90u43";
    System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\d+");
    ArrayList list = new ArrayList();
    System.Text.RegularExpressions.MatchCollection matchs = regex.Matches(str);
    for(int i = 0; i < matchs.Count; i++)
    {
        String tmp = "000000000" + matchs[i].Value;
        list.Add(tmp.Substring(tmp.Length - 9, 9));
    }
      

  2.   

    如果要匹配得用循环完成,何不用替换??把非数字给过滤出去....
    using System;
    using System.Collections.Generic;
    using System.Collections;
    using System.Text;
    using System.Text.RegularExpressions;
    public class HelloWorld
    {
        static void Main(string[] args)
        {
            int intNeedNumber = 9;
            string tmpInput = "478sd78".Trim();
            string strResults = Regex.Replace(tmpInput, "[^0-9]", "");
            int length = intNeedNumber - 1;
            int intResultsLength = strResults.Length;
            if (intResultsLength < length)
            {
                strResults = strResults.PadRight(9,'0');
            }
            else if (intResultsLength > length)
            {
                strResults = strResults.Substring(0, intNeedNumber);
            }
            Console.WriteLine(strResults);
            Console.ReadKey();
        }
    }