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

Is there a way to add the ']' special character in my regex, when it normally ends my proposition?

I am trying to fit ‘]’ into my regex that lets any string pass as long as it doesn’t have a certain set of special characters. However, the IDE shows me that it ends the expression:

message: Joi.string().regex(/^[^<>#*=+^}[]+$/).required()
//current working code


message: Joi.string().regex(/^[^<>#*=+^}[]]+$/).required()
//what I am trying to add

>Solution :

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

You can escape special character using \

So you can use:
(/^[^<>#*=+^}[\]]+$/)
which will escape the first ] allowing it to be viewed as a regular symbol.

If you are new to regular expressions, try regex101.com. It does a good job of breaking them down for you.

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