寻找“$ {sometext}”的正则表达式

时间:2016-09-14 14:57:21

标签: c# regex

我发现了这个 "\\${(.*?)\\}

所以我试过了: new Regex(@"\\$\\${(.*?)\\}");

但这似乎不起作用,这里的问题是什么?

1 个答案:

答案 0 :(得分:3)

我会使用new Regex(@"\${(.*?)}");

让我们分析一下:

(@"\\$\\${(.*?)\\}");
   ^^^^^^      ^^^
   ||||||      |||-- Your don't need to double your slashes in a literal string.
     \  |        |       
      \ |        |
       \|--------|-- You have 2 "$" and you just want one
                 |
                 |-- You don't need to escape "{" since it doesn't enclose digits
                     and can't be interpreted as a length attribute.