Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Complex regular expression - alphanumeric, hyphen-space-hyphen, + and ++

Tags:

regex

I need a regular expression supporting alphanumeric, hyphen, hyphen-space-hyphen, + and ++.

For the alphanumeric with hyphen, space and plus, I can give something like /^[a-zA-Z0-9- +]*$/. Can I use +{0,2} inside the square bracket?

Anybody please help me to complete my required regular expression.

like image 583
Saidh Avatar asked Dec 18 '25 19:12

Saidh


1 Answers

Try this:

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

It will accept +ab, ++ab, ++ab++, ++ab++a+, etc., but it will not accept +++a, ++ab+++, etc.

like image 74
Noufal Avatar answered Dec 21 '25 20:12

Noufal