且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用正则表达式查找和替换单词

更新时间:2022-11-12 07:46:55

正则表达式是聪明的野兽,Rexex的重载之一.替换使用匹配评估程序委托: http: //msdn.microsoft.com/en-us/library/cft8645c.aspx#Y0 [
Regexes are clever beasts, one opf the overloads for Rexex.Replace uses a match evaluator delegate: http://msdn.microsoft.com/en-us/library/cft8645c.aspx#Y0[^] which allows you to do further processing on the text matched by the Regex.
If you write your routine to compare the match text as supplied by the Match parameter text, you can replace only those strings you are interested in. The link has an example.


我认为这篇文章可能会有帮助.

查找并替换为正则表达式 [ ^ ]
I think this article could be of some help.

Find and Replace with Regular Expressions[^]


谢谢OriginalGriff,为我提供了正确的指导

我自己做过的

Thanks OriginalGriff, for guide me to right way

i have done it myself

Function DumpHRefs(ByVal inputString As String) As String
    Dim HRefPattern As String = "href\s*=\s*(?:""(?<1>[^""]*)""|(?<1>\S+))"
    Dim r3 As New Regex(HRefPattern, RegexOptions.IgnoreCase)
    inputString = r3.Replace(inputString, AddressOf smily_replace)

    Return inputString
  End Function

  Function smily_replace(ByVal newstr As Match) As String
    Dim x As String = newstr.ToString()

    For Each word In arrString
      If x.Contains(word) Then x = x.Replace(word, "")
    Next

    Return x
  End Function