本文介绍了使用传统的ASP定期EX pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们有一些经典的ASP网站,我对他们的工作莉儿一点,我想知道我怎么能写一个正前pression检查,并提取匹配的前pression:
We have some Classic asp sites, and i'm working on them a lil' bit, and I was wondering how can I write a regular expression check, and extract the matched expression:
恩pression我是在脚本的名字
所以我们说,这
the expression I have is in the script's nameso Let's say this
Response.Write Request.ServerVariables("SCRIPT_NAME")
打印出:
review_blabla.asp
review_foo.asp
review_bar.asp
我怎样才能获得布拉布拉
,富
和栏
从那里?
感谢。
推荐答案
虽然Yots'答案几乎肯定是正确的,你可以实现你少了很多code和较为清晰地寻找的结果:
Whilst Yots' answer is almost certainly correct, you can achieve the result you are looking for with a lot less code and somewhat more clearly:
'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
此外,我还没有找到gskinner.com 更好正则表达式的操场比之一,它的辉煌的尝试您正则表达式图案潜入code之前。
这篇关于使用传统的ASP定期EX pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!