Regex number and hyphen
regex
Solution
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
Problem
I'm trying to match number with regular expression like: ``` 34-7878-3523-4233 ``` with this: ``` ^[0-9][0-9-]*-[0-9-]*[0-9]$ ``` But the expression also allow 34--34--------88 So how can I allow only one hyphen between the number?