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

require regex to find Tranlation keys inside the html text

I need to find translation keys inside html text:
e.g. "<p class='m-0 p-0 mx-2 d-inline-block'>{{'MEDIA_SERVER_URL' | translate}}: </p>";

I need to find MEDIA_SERVER_URL in this. conditions like that

  1. Should be enclosed by either single quote or Double quotes.
  2. Should have all CAPS
  3. Should be inside {{}} pair braces.

ChatGpt give answer like var pattern = /{{?'([^']+?)'[\s\S]*?[A-Z_]+}?/g;, that’s not working.

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

Can anyone please help me. I don’t have that expertise in regex to solve this myself.
Thanks

>Solution :

The pattern is /{{\s*(['"])([_A-Z]+)\1\s*\|\s*translate\s*}}/g and the keys you’re looking for should be in group#2.

You may go to https://regexr.com/7tnih to have a try.

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