首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

vb.net正则表达式,有人能解释一下吗?该怎么处理

2012-04-02 
vb.net正则表达式,有人能解释一下吗?VB.NET codeDim reg As New System.Text.RegularExpressions.Regex(w

vb.net正则表达式,有人能解释一下吗?

VB.NET code
Dim reg As New System.Text.RegularExpressions.Regex("w[\w]*")Dim m As System.Text.RegularExpressions.MatchCollection = reg.Matches("wire")Dim alnum As IEnumerator = m.GetEnumeratorWhile alnum.MoveNext          MsgBox(alnum.Current.groups(0).value)End While Dim reg As New System.Text.RegularExpressions.Regex("w[\w]*")        Dim m As System.Text.RegularExpressions.MatchCollection = reg.Matches("wire", System.Text.RegularExpressions.RegexOptions.IgnoreCase)        Dim alnum As IEnumerator = m.GetEnumerator        While alnum.MoveNext            MsgBox(alnum.Current.groups(0).value)        End WhileDim reg As New System.Text.RegularExpressions.Regex("[\w]*")        Dim m As System.Text.RegularExpressions.MatchCollection = reg.Matches("wire", System.Text.RegularExpressions.RegexOptions.IgnoreCase)        Dim alnum As IEnumerator = m.GetEnumerator        While alnum.MoveNext            MsgBox(alnum.Current.groups(0).value)        End While




第一个的结果是匹配的,第二个却没有,主要是加了个System.Text.RegularExpressions.RegexOptions.IgnoreCase,这不只是不区分大小写吗?第三个输出的竟然是ire,明显第一个字符不见了,难道System.Text.RegularExpressions.RegexOptions.IgnoreCase就直接忽略第一个符了?

[解决办法]
VB.NET code
        Dim m As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches("wire",                                                    "w[\w]*", System.Text.RegularExpressions.RegexOptions.IgnoreCase)        Dim alnum As IEnumerator = m.GetEnumerator        While alnum.MoveNext            MsgBox(alnum.Current.groups(0).value)        End While 

热点排行