Regex allow a string to only contain numbers 0 - 9 and limit length to 45

后端 未结 8 850
轮回少年
轮回少年 2020-12-02 13:57

I am trying to create a regex to have a string only contain 0-9 as the characters and it must be at least 1 char in length and no more than 45. so

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 14:42

    For this case word boundary (\b) can also be used instead of start anchor (^) and end anchor ($):

    \b\d{1,45}\b
    

    \b is a position between \w and \W (non-word char), or at the beginning or end of a string.

提交回复
热议问题