Help with Regex 2

Hello Again EE,

Mostly for Kaufmed and TerryOpus,

with that regex:


what if I would like the dash to be optional after GL_  ? (dash is between some numbers)
also It might happen there would be more dashes like this:

GL_100-390-3992-1 (several dashes)
or this:
GL_9383-1384  (1 dash)
or this:
GL_1900000    (no dash)
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

To match the dash 0 or 1 times:

PhilippeRenaudAuthor Commented:
what if 0,1,2,3,4,5,....999 ?
You want to match the number if the dash is there or if it is not.  If it is there, it will not be there more than once.  So we need to match the dash 0 or 1 time. The matching of digits has not changed.  Try it for yourself.
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

PhilippeRenaudAuthor Commented:
Its not working if I try with this :


the match will be only on :   103923-323

result would need to match:    103923-323-433334
Okay, I see what you mean.  My mistake in reading your question. You really want to match multiple sets of digits and hyphens if present...


If you don't care if the last digit is also a hyphen:


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
PhilippeRenaudAuthor Commented:
Thanks !
käµfm³d 👽Commented:
For the multiple digit-hyphen combos:


Open in new window

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.