I would like to write a regular expression which matches one or more occurrences of:
- exactly two open curly braces, followed by
- zero or more spaces, followed by
- a dynamic string, followed by
- zero or more spaces, followed by
- exactly two closed curly braces
Let's say I have a fixed string hello. Then the regular expression which matches the above-mentioned pattern would be:
/({{\s*hello\s*}}){1,}/gi
In TypeScript, this would become:
const regExp: RegExp = /({{\s*hello\s*}}){1,}/gi;
If I were to use that regular expression with the following array of strings I would get these results:
- {{ hello }}: 1 match
- {{ hello}}: 1 match
- {{hello }}: 1 match
- {{hello}}: 1 match
- {hello}}: 0 matches
- {{hello}: 0 matches
- { hello }: 0 matches
- {{hello}}, how are you? {{ hello }}: 2 matches
- {{hello}}, how are you? {{ hello }} {{hello}}: 3 matches
- {{HELLO}}: 1 match
However, I am not able to achieve the same result by using a dynamic string.
