求正则表达式语句,提取两个单词之间的内容
例如:Begin ABC Begin 这里是我要提取的内容 End BBB End;
红色字体是我提取的内容,即:提取“Begin”...“End”之间的部分?
关键问题是“Begin”...“End”的前面还有嵌套,对我有些难度,希望大家帮我,谢谢!!!
then if w1>-1 then w2=i exit for end if
Function regular(s As String) As String Const Head = "Begin" Const Tail = "End" Dim l As Integer, r As Integer, a As String If s <> "" Then l = InStrRev(s, Head) '找到最后一个Begin的位置 r = InStr(s, Tail) '找到第一个End的位置 If l=0 Or r=0 Then Exit Function '避免Begin、End不成对造成嵌套进入死循环或执行错误 Text2 = Text2 & Mid$(s, l + Len(Head), r - l - Len(Head)) & " " s = Replace(s, Mid$(s, l, r + Len(Tail) - l), "") regular s '自己调用自己,嵌套处理,直到字符串为空跳出嵌套 End If End Function Private Sub Command1_Click() Dim s As String Text2 = "" s = Text1 regular s End Sub Private Sub Form_Load() Text1 = "" Text2 = "" End Sub