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(?=})/gthis 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?
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 :
- Use
+to match one or more char. - Use
\to escape regex special chars