求一正则表达式,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请各位大侠赐教!谢谢了
str="9-3-44" false
str="8999" true
str="8+3-23" rue
str="8u+9-3" false请各位大侠赐教!谢谢了
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*\+*$"));
}
}
}
Console.WriteLine(System.Text.RegularExpressions.Regex.IsMatch(str, @"^(\d*\+*)*\-{0,1}(\d*\+*)*$"));
(?s)^(?=^[^-]*(-[^-]*){0,1}$)\d+([+-]\d+)*$