user3523475 user3523475 - 1 year ago 77
Javascript Question

JavaScript RegEx zero or one string in bracets

I need to match a given string (let it be 'start') with possible presence of a special ending or without it. The ending could be '(a)' or '(b)' or '(c)', I mean one of letters a, b or c in braces. If there is no braces or just one brace or they are in the wrong order than there should be no match. Broke my head trying to make appropriate RegEx.
So full list of possible matches:


Any other input should produce no match.

Answer Source

Here it is : ^start(\([abc]\))?$

for better reading you can go to regex101

here it is what it does : enter image description here