2013-04-29 70 views
0

我需要的正則表達式(Regex.Match),用於下面的符號的任何組合CANT創建正則表達式

a-z 
A-Z 
0-9 
()[]_-. 

長度是從2到16個符號。 例子:

asdqwe23)) 
asd[-_]QWE 
0(.)qwe[zz_-]. 

伊夫嘗試這種

^[\w\d\r\n\d\[\]\(\)-_]{2,16} 

,但它不工作,它允許@#$%^ * &除第一次任何地方的符號!另外17個長度的字符串也返回isSucsess true。

回答

3

使用這個表達式^[_a-zA-Z\d\[\]\(\)\-\.]{2,16}$

1

使用

var input = "asd[-_]QWE"; 
var result = Regex.Matches(input, @"^[A-Za-z0-9\(\)\[\]_\-\.]{2,16}$"); 
Console.WriteLine(result[0]); 
+0

您正則表達式匹配17+長度字符串 – 2013-04-29 13:59:07

+0

啊多數民衆贊成意見的權利感謝 - 編輯 – WhileTrueSleep 2013-04-29 14:04:21