如何创建拒绝正则表达式

时间:2016-05-08 23:53:42

标签: regex vb.net

我是正则表达式的初学者。我想为拒绝字符列表编写一个正则表达式。这些字符包括Dim login As String Dim password As String Dim reject As String = "[$^\/()|?+*[]{}><]" Dim rgx As New Regex(reject) Dim matches As MatchCollection Dim matches2 As MatchCollection login = txtLogin.Text password = txtPassword.Text matches = rgx.Matches(login) matches2 = rgx.Matches(password) If matches.Count > 0 Then loginErr.Text = "Login can not contain ^ $ \ / ( ) | ? + * [ ] { } ><" Else loginErr.Text = "" End If If matches2.Count > 0 Then passwordErr.Text = "Password can not contain ^ $ \ / ( ) | ? + * [ ] { } ><" Else passwordErr.Text = "" End If

感谢任何帮助。

编辑: 我想测试VB webform应用程序中是否存在任何这些字符。

{{1}}

1 个答案:

答案 0 :(得分:0)

我在您的代码中看到的唯一问题是您没有正确转义字符类中的特殊字符\^]

Dim reject As String = "[$\^\\/()|?+*[\]{}><]"