Regular expression to allow only one special character Middle on the string

Need a regex to match below text

testt test

Should start with a-zA-Z then space or - or / then a-zA-Z. (- /) should be optional

Tried with this. didn’t work

^[a-zA-Z][/- ]?[a-zA-Z]

>Solution :

It is a bit hard to understand what you are looking for but it looks like what you want is something more like ^[a-zA-Z]+[\/\- ]?[a-zA-Z]+

You are missing is + after the [a-zA-Z] to indicate there is one or more, and then you need \ infront of - and / to escape

Leave a Reply