Complex regex - alphanumeric, hyphen-space-hyphen, + and ++

I need a regex that supports alphanumeric, hyphen, hyphen-space-hyphen, + and ++.

For alphanumeric with hyphens, space and plus, I can give something like /^[a-zA-Z0-9- +]*$/

. Can I use +{0,2}

inside a square bracket?

Someone please help me fill in the required regexp.

+3


source to share


1 answer


Try the following:

^(\+{0,2}[a-zA-Z0-9\-]+)*\+{0,2}$

      



He will +ab

, ++ab

, ++ab++

, ++ab++a+

and so on, but will not accept +++a

, ++ab+++

etc.

+3


source







All Articles