Reputation: 1621
I need a pattern that would accept
Valid matches:
12
123456789
423432423423423423423432
56-1
56-23456789
78-12
78-34234234234234234234234
Invalid matches:
1
1-
11-
1-112
44-2342424
64-4345334
55-sdrfewrwe
56-
5678-234324123423154
Here is my pattern so far:
[0-9]{2}-[0-9]{1,}|^[0-9]+$
Upvotes: 2
Views: 149
Reputation: 626794
You can use
^(?:(?:56|78)-[0-9]+|[0-9]{2,})$
See the regex demo.
Details:
^
- start of string(?:
- start of a non-capturing group with two alternatives:
-
56or
78,
-`, one or more digits|
- or[0-9]{2,}
- two or more digits)
- end of the group$
- end of string.Upvotes: 1