Regex Pattern number1 to number2

前端 未结 3 1434
耶瑟儿~
耶瑟儿~ 2021-01-21 22:37

I\'m searching for a pattern for the following behavior:

number1-number2
number1: Can be everything >= 0 and <= int.MaxValue
number2: Can be everything >         


        
3条回答
  •  渐次进展
    2021-01-21 23:13

    Regex can only be used to match the numbers. Post that a comparison operation needs to be done.

    string num="number1-number2";//where (number1 & number2)=numeric val
    MatchCollection stringVal= Regex.Matches(num,@"\d+");
    int num1=Convert.ToInt32(stringVal[0].Value);
    int num2=Convert.ToInt32(stringVal[1].Value);
    if(num1>=0 && num1<=int.MaxValue && num2>=num1 && num2<=int.MaxValue)
        return true;
    else
       return false;
    

    will give you an array containing the the numbers

提交回复
热议问题