VBA + RegEx + Range.Replace

我有一些使用JavaScript的正则expression式的知识,但现在我想在Excel和VBA中使用它,我有一些问题得到它的工作。

我想用>abcreplace<br>> abc

在JavaScript中我使用>([a-zA-Z0-9])<br>> $1 ,但在这里我不知道该怎么做。

我也想用Range.Replace函数来使用它,比如:

 oRange.Replace What:=">abc", Replacement:="<br>> abc", MatchCase:=False 

任何帮助将不胜感激。

也许像这样的例程。 这将用模式search指定的范围并replace内容…

希望有所帮助。

 Public Sub RegExMatchAndReplace(ByVal Pattern As String, ByVal Data As Range, ByVal Replace As String) Dim oRegEx As New RegExp Dim rPtr As Range For Each rPtr In Data With oRegEx .Global = True .MultiLine = True .IgnoreCase = True .Pattern = Pattern rPtr.Value = oRegEx.Replace(rPtr.Value, Replace) End With Next End Sub