当前位置:编程学习 > C#/ASP.NET >>

正则表达式如何写?

一个字符串如何判断他是数字字母或减号,否则的话清空他
请写一个完整的例子 --------------------编程问答--------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace CATesting
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "-1832jskfksHJaklfdk89skl7kks-";
            Regex re = new Regex(@"^[-0-9a-zA-Z]*$", RegexOptions.IgnoreCase);
            if (!re.IsMatch(str))
            {
                str = string.Empty;
            }
            Console.WriteLine(str);
            Console.ReadKey();
        }
    }
}
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,