2016-09-14 67 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查看編輯說明 –