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

use regex to check that start of user input has exactly two curly brackets

I’m trying to make sure that user input is exactly {{user_input}} in regards to the brackets. text can be anything as long as it’s a number or character. {{(.*?)}} works to make sure that the two brackets exist at the beginning and end of the input but I also want to make sure there are only two brackets. I’ve tried [^{]{{(.*?)}}[^}] and {{2}(.*?)}{2}, but it still counts {{{user_input}} as valid.

>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

(?<![{])a => There must not "{" character before the "a"

a(?![}]) => There must not "}" character after the "a"

a([^{}]*)a => All characters except "{" and "}" between "a"s

Solution:

(?<![{]){{([^{}]*?)}}(?![}])

Sample: https://regex101.com/r/OiLk8S/1

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