Regex number and hyphen

前端 未结 3 1753
傲寒
傲寒 2021-01-18 20:57

I\'m trying to match number with regular expression like:

34-7878-3523-4233

with this:

^[0-9][0-9-]*-[0-9-]*[0-9]$
<         


        
3条回答
  •  爱一瞬间的悲伤
    2021-01-18 21:26

    Your regex:

    See it in action: Regexr.com

    ^[0-9]+(-[0-9]+)+$
    

    Matches:

    1-2
    1-2-3
    

    Doesn't match:

    1
    1-
    1-2-
    1-2----3
    1---3
    

提交回复
热议问题