正则表达式 – 使用经典的asp进行正则表达式

我们有一些经典的asp网站,我正在研究它们,我想知道如何编写正则表达式检查,并提取匹配的表达式:

我所拥有的表达式是脚本的名称
所以我们这样说吧

Response.Write Request.ServerVariables("SCRIPT_NAME")

打印出来:

review_blabla.asp
review_foo.asp
review_bar.asp

我怎么能从那里得到blabla,foo和bar?

谢谢.

虽然Yots的答案几乎肯定是正确的,但您可以通过更少的代码和更清晰的方式实现您正在寻找的结果:
'A handy function i keep lying around for RegEx matches'
Function RegExResults(strTarget,strPattern)

    Set regEx = New RegExp
    regEx.Pattern = strPattern
    regEx.Global = true
    Set RegExResults = regEx.Execute(strTarget)
    Set regEx = nothing

End Function

'Pass the original string and pattern into the function and get a collection object back'
Set arrResults = RegExResults(Request.ServerVariables("SCRIPT_NAME"),"review_(.*?)\.asp")

'In your pattern the answer is the first group,so all you need is'
For each result in arrResults
    Response.Write(result.Submatches(0))
Next

Set arrResults = nothing

另外,我还没有找到更好的RegEx playground than Regexr,在试用代码之前试用你的正则表达式是很棒的.

相关文章

正则替换html代码中img标签的src值在开发富文本信息在移动端...
正则表达式
AWK是一种处理文本文件的语言,是一个强大的文件分析工具。它...
正则表达式是特殊的字符序列,利用事先定义好的特定字符以及...
Python界一名小学生,热心分享编程学习。
收集整理每周优质开发者内容,包括、、等方面。每周五定期发...