-4

I have a string from which I need to fetch the ones with {{ ... }} pattern and replace them with the evaluated value.

Note: Some methods will be placed with in this {{abc();}}.I need to evaluate these methods and replace it with the respective outputs.

string abc="/*html$**{{abcd();}}**//*dhf//**{{ef();}}** ";
string pattern="*{{*}}*";
MatchCollection collection = Regex.Matches(abc, pattern);

I tried using this pattern.But it is throwing the below exception.

"{"parsing \"{{}}*\" - Quantifier {x,y} following nothing."}"

1 Answers1

0

Okay you definitely need to learn more about regex patterns since your pattern is not even compilable...

For beginners this pattern {{[a-z]*\(\);}} will get you {{abc();}}.
It's very simple since the only chars you need to escape are ( and )
These are some of the special chars of a regex that split a pattern into "capturing groups" so if you want to match them you need to escape them by putting \ infront of them. The same goes for * for example.

Use a site like https://regex101.com/ for testing regexes(?) and to develop my given pattern to your specific needs.

The website offers a lot of explanation on how each of the symbols in the patterns work and even shows you when your pattern string is flawed with errors.

Pio
  • 513
  • 4
  • 19