Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

Need a regex to match below text

testword
testWord
TestA/Test
testt test
TestA-Test

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

Tried with this. didn’t work

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

^[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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading