2011-11-03 41 views

回答

0

"[^"]+"怎麼樣?它匹配一個報價,後跟一個或多個非引號字符,後跟另一個報價。

如果您只希望允許使用ASCII字母數字字符(A-Z, a-z, 0-9),請使用":a+"

順便說一下,這裏是the docs for VS 2010 regular expressions

+0

在帶有10000個代碼的類中,有以「and end with」開頭的單詞的山峯。例如「asdf」,「fgdg」,「a34」,「3tvcc」。我需要找到以'''開頭和結尾的所有單詞' –

+0

好吧,這樣正則表達式應該可以工作。你試過了嗎? –

+0

它工作的很完美! –

0
string sPattern = "^\"(.*)?\""; //perform non greedy match until it finds first " 

    foreach (string s in numbers) 
    { 

     if (System.Text.RegularExpressions.Regex.IsMatch(s, sPattern)) 
     { 
      System.Console.WriteLine(" - valid"); 
     } 
     else 
     { 
      System.Console.WriteLine(" - invalid"); 
     } 
    }