2014-01-09 51 views
0

我有一些旧的.NET代码,在一个SQL字符串正则表达式(#,?,:)[a-zA-Z0-9] * _ *是什么意思?

System.Text.RegularExpressions.MatchCollection collection = 
System.Text.RegularExpressions.Regex.Matches(icmd.CommandText, 
"(#,?,:)[a-zA-Z0-9]*_*"); 

我不知道它是如何匹配的搜索参数。任何人都可以解释我?

+1

不是解决你的问题,但我怀疑'(#,:)'节错误,应该是'[#?:]'。 – porges

+0

是的,我认为你是对的,它可以帮助我很多 – moodym

回答

6

看下面的图解释它。

enter image description here

UPDATE:在下面的代码#,,:abc12_匹配。

System.Text.RegularExpressions.MatchCollection collection = 
System.Text.RegularExpressions.Regex.Matches("#,,:abc12_", "(#,?,:)[a-zA-Z0-9]*_*"); 
+0

供将来参考,你用什么应用程序生成了该图? – norlesh

+1

它适用于Javascript,但也适用于其他语言... http://www.regexper.com/ –

+0

感谢您的帮助 – moodym

3

参考this对正则表达式有任何疑问。

(#,?,:)[a-zA-Z0-9]*_*

1st Capturing group (#,?,:) 
# matches the character # literally 
,? matches the character , literally 
Quantifier: Between zero and one time, as many times as possible, giving back as needed [greedy] 

,: matches the characters ,: literally 
[a-zA-Z0-9]* match a single character present in the list below 
Quantifier: Between zero and unlimited times, as many times as possible, giving back as needed [greedy] 
a-z a single character in the range between a and z (case sensitive) 
A-Z a single character in the range between A and Z (case sensitive) 
0-9 a single character in the range between 0 and 9 


_* matches the character _ literally 
Quantifier: Between zero and unlimited times, as many times as possible, giving back as needed [greedy] 

方式:?它可以匹配#,,:anycharactorstring#,,:anycharactorstring_#,:anycharactorstring#,:anycharactorstring_____

+0

感谢您的帮助 – moodym

相关问题