求一正则表达式,C#字符串中只能是数字或“-+”,而且“-”最多只能存在一个  System.Text.RegularExpressions.Regex.IsMatch(str,"正则表达式")  如果str="45u99"则返回false
      str="9-3-44"     false
      str="8999"       true
      str="8+3-23"     rue
      str="8u+9-3"     false请各位大侠赐教!谢谢了

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;namespace CSharp
    {
        class Program
        {
            static void Main(string[] args)
            {
                string str = "8999-2-3";
                
                Console.WriteLine(System.Text.RegularExpressions.Regex.IsMatch(str, @"^\d*\+*\-{0,1}\d*\+*$"));
            }
        }
    }
      

  2.   

    这个是对的
          Console.WriteLine(System.Text.RegularExpressions.Regex.IsMatch(str, @"^(\d*\+*)*\-{0,1}(\d*\+*)*$"));
      

  3.   


    (?s)^(?=^[^-]*(-[^-]*){0,1}$)\d+([+-]\d+)*$
      

  4.   

    LCL_data,fengjian_428  谢谢两位!辛苦了