JavaScript Regex for 0-9/A-Z pattern match with Hyphen

I'm looking for a  Javascript regx that will detect a-z (case insensitive)  or 09 as a group and then a hyphen followed by any group  of a-z or 09  etc. Always will start/end with (a-z or 09) For example:

a12dd3-23-fff-11n3N33n3-988
9fkr-rtt488-344-45
r5999999Rrp-4-yei388dfi3-3444-fjj577-23
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
1234-567-8-922-222222-2-1111
894359Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zc2Commented:
I would try
([a-zA-Z0-9]+-?)+

Open in new window

https://regexr.com/3vf1b
0
894359Author Commented:
Hi zc2,
That doesn't seem to work,  as it allows anything I've tested, good or bad?
0
zc2Commented:
Could you post an input string which should not match?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

894359Author Commented:
Hi Zc2,
Try these two:

*********8
s@#$%^^
0
zc2Commented:
With added begin (^) and end ($) string markers those input lines are now excluded:
^([a-zA-Z0-9]+-?)+$

Open in new window

Test it here:
https://regex101.com/r/GVxhMn/1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
894359Author Commented:
HI,
I tested again and it still works for strings ending with a hyphen but it shouldn't. Examples that should fail:

xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-xxxx-
123-sx2M-34-
0
Shaun VermaakTechnical Specialist/DeveloperCommented:
[a-zA-Z0-9\-]+

Open in new window

https://regex101.com/r/hRXTDF/1
0
zc2Commented:
How about this:
^([a-zA-Z0-9]+-)+[a-zA-Z0-9]+$

Open in new window


https://regex101.com/r/GVxhMn/3
0
894359Author Commented:
Hi Shaun,
I believe it still allows strings ending with a hyphen which I do not want.

Thanks!
0
894359Author Commented:
This works:  ^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$
0
894359Author Commented:
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.