正则表达式计算替换次数

时间:2015-10-30 15:07:17

标签: regex vb.net replace count

VB2012:使用正则表达式替换某些短语。有没有办法报告实际有多少替换。

    Dim regex As Regex = New Regex("^PENALTY", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
    Dim replacement As String = "PENALTY PER MINUTE"
    Dim result As String = regex.Replace(input, replacement)

    Dim p as Integer = 0 'how do I get this???
    MsgBox(p.ToString &  " replacements were made")

0 个答案:

没有答案