Regular expression where part of string must be number between 0-100

后端 未结 7 787
有刺的猬
有刺的猬 2020-12-02 02:23

I need to validate serial numbers. For this we use regular expressions in C#, and a certain product, part of the serial number is the \"seconds since midnight\". There are

7条回答
  •  忘掉有多难
    2020-12-02 02:29

    I would use regex combined with some .NET code to accomplish this. A pure regex solution isn't going to be easy or efficient to handle large number ranges.

    But this will:

    Regex myRegex = new Regex(@"\d{9}-(\d{5})-\d{6}");
    String value = myRegex.Replace(@"654984051-86400-231324", "$1");
    

    This will grab the value 86400 in this case. And then you'd just check if the captured number is between 0 and 86400 as per Jason's answer.

提交回复
热议问题