Reputation: 77
I want to match a pattern with regex, the pattern is:
A-Za-z1-9[0-9-0-9]
so for example:
test1[1-50]
Can you help me ?
Solution update:
^[A-Za-z0-9]+\[[0-9]+-[0-9]+]$
Upvotes: 1
Views: 160
Reputation: 7081
Use this regex: [A-Za-z]+[1-9]\[[0-9]+-[0-9]+\]
. You might also want to add \b
at the start of the regex to match only after non words character.
[A-Za-z]+
matches things like test
, only letters are accepted, one or more times[1-9]
matches a any digit but 0\[[0-9]+-[0-9]+\]
matches one or more digits twice and separated with -
. All this must be enclosed with square brackets. (You need to escape those with \
because they are metacharacters)Upvotes: 1