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

How to find all of the string that match a pattern "{*.*}"

On my page, I will received a string from user input and need to find all of the parts that is something like "{T001.Name}" or "{T002.Username}", and replace with proper value from a JSON Array.
I am not familiar with RegEx so I am kind of struggle with this.

I try some patterns like the below, but nothing work.

  • /(?<={)\w.\w(?=})/g this will work with any string that have 3 character between the "{}", so not a solution.

I understand that the "\w" will only return 1 character, and the dot mean any character, so how can I change the above to get the correct pattern?

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

EDIT: For the purpose of RegEx, I would like to use the matchAll function to return an array with all string that match the pattern "{.}", then I will loop through it and run my "replace" code.

>Solution :

Try this regex /(?<={)\w+\.\w+(?=})/g

Tip :

  1. Use + to match one or more char.
  2. Use \ to escape regex special chars
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