2015-04-02 76 views
1

我需要檢查下面提到的特殊字符以及在我的數據擴展的拉丁字符

特殊字符[email protected]©#$%^&*()_+{}|:"<>?``€[]\;',./

變音符é, ö, ò, etc

我已經試過[^a-z],但因爲我需要它不工作,還可以拍攝無用字符

你能幫我建議正確的正則表達式嗎?

+0

請提供更多的信息。你究竟想達到什麼目的? – npinti 2015-04-02 10:17:58

回答

3

在.NET中,您也可以使用特殊字符類。您提供的信件來自\p{IsLatin-1Supplement}Unicode character set

正則表達式,然後可以

[\p{IsLatin-1Supplement}[email protected]©#$%^&*()_+{}|:"<>?`€\[\]\\;',./]+ 

[\p{IsLatin-1Supplement}\p{P}\p{S}]+ 

,因爲您提供的來自符號和標點符號Unicode字符集的符號。

示例代碼以從字符類匹配單個字符:

var rx = new Regex(@"[\p{IsLatin-1Supplement}\p{P}\p{S}]"); 
var str = "[email protected]©#$%^&*()_+{}|:\"<>?€[]\\;',./`éöò"; 
var all = rx.Matches(str).Cast<Match>().ToList(); 

輸出(在VS2012):

enter image description here

+0

你好,我也在尋找像100,100.00這樣的有效價格值的正則表達式,並且數字應該沒有負號....是否有可能使用正則表達式 – Rakesh 2015-04-02 11:45:05

+0

@Rakesh:我不知道你到底在找什麼。如果它是實時驗證,那麼這並不容易,因爲你必須使用預見。如果不是,那真的很簡單。但價格驗證,我只是使用C#Decimal.TryParse()(https://msdn.microsoft.com/en-us/library/ew0seb73(v=vs.110).aspx?cs-save-lang= 1個CS-LANG = CSHARP#代碼片斷-1)。請發佈你的問題,你一定會得到一個討厭的。 – 2015-04-02 11:54:46

+0

你好,請找到有關價格驗證的問題http://stackoverflow.com/questions/29415527/c-sharp-price-validation-using-regular-expression-other-way – Rakesh 2015-04-02 14:31:32