请教一个关于vbscript的正则表达式

来源:百度知道 编辑:UC知道 时间:2024/05/14 10:48:15
输入这样一个字符串
studentid Kobe studentid LBJ end

我想得到所有位于"studentid"和"end"之间的内容,也就是希望得到两个结果:
1,Kobe studentid LBJ
2, LBJ

我试了一下这样的写法
Dim InStr, regEx, Match, Matches
InStr = "studentid Kobe studentid LBJ end"

Set regEx = New RegExp

regEx.Pattern = "studentid(.*)end"
regEx.Global = True
Set Matches = regEx.Execute(InStr)
ResStr = ""

For Each Match in Matches
ResStr=Match.Value
Document.write ResStr
Next

但是好像只能得到 Kobe studentid LBJ 一个值
有什么办法能把这两个匹配都拿到呢?
谢谢!

Kobe 后边没有end当然匹配不到了。而且*默认的是贪婪模式,会一直匹配下去直到不能再匹配为止。你要的却是非贪婪模式,即遇到匹配就停止。
*?就可以了

Kobe 没有 end