要求找出以下类型的字符串:\\xxx\xx\xx\xx.doc必须以\\开头,中间至少有1个\,xx代表任意数量的字母,数字或者空格,最后以.doc结尾。
在线等,感谢!

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Globalization;
    using System.IO;
    using System.Data.SqlClient;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string[] str = new string[] { @"\\xxx\xx\xx\xx.doc",@"\\xxx\xx.doc",@"\\xxx\xx\xx\xx.dox" };
                Regex re = new Regex(@"^(?i)\\\\[ 0-9a-z]+(\\[ 0-9a-z]+)+\.doc$");
                foreach (string s in str)
                {
                    if(re.Match(s).Success)
                    Console.WriteLine(re.Match(s).Value);
                }
                      }
        }
    }
    \\xxx\xx\xx\xx.doc
    \\xxx\xx.doc
    Press any key to continue . . .