2016-09-14 70 views
1

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

所以,我想: new Regex(@"\\$\\${(.*?)\\}");

但这似乎并不在这里工作,什么问题呢?

+1

这有什么错[string.Contains(https://msdn.microsoft.com/en-us/library/dy85x1sa(V = vs.110)的.aspx)? – Liam

+0

你有一个罕见的问题:**只有一个*美元*太多... **第二个'''不需要...尝试'新的正则表达式(@“\\ $ \\ {(。*?) \\}});' – ppeterka

+0

特别阅读[这个答案](http://stackoverflow.com/a/5848360/542251) – Liam

回答

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. 
+0

之间的文本谢谢,看起来不错:) – ASfdsa33

+0

假设错误然后是OP的尝试是逃避斜线在字符串文字里面? –

+0

@ ASfdsa33查看编辑说明 –