当前位置: 移动技术网 > IT编程>开发语言>正则 > [asp]中的正则表达式运用代码

[asp]中的正则表达式运用代码

2017年12月12日  | 移动技术网IT编程  | 我要评论
今天在改一套b2b的电子商务系统时,发现asp正则,虽然用asp很久了,但从来没用过正则表达式,这套系统中有个正则的函数很不错,自己看吧。
复制代码 代码如下:

<%  
function regexptest(patrn, strng) 
    dim regex, match, matches   ' 建立变量。 
    set regex = new regexp   ' 建立正则表达式。 
     regex.pattern = patrn   ' 设置模式。 
    regex.ignorecase = false   ' 设置是否区分字符大小写。 
    regex.global = true   ' 设置全局可用性。 
    set matches = regex.execute(strng)   ' 执行搜索。 
    for each match in matches   ' 遍历匹配集合。 
    on error resume next 
    retstr = retstr & match.value&"|" 
    next 
    regexptest = retstr 
end function 

 str = "我来自#5565#哈哈" 
 strinfo = regexptest("#\w+(\((\b[,0-9]+\b)?\))?#", str) 
 response.write(strinfo) 
%> 

再看一例:

复制代码 代码如下:

function nohtml(str) 
     dim re 
     set re=new regexp 
     re.ignorecase =true 
     re.global=true 
     re.pattern="(\<.*?\>)" 
     str=re.replace(str,"") 
     re.pattern="(\<\/.*?\>)" 
     str=re.replace(str,"") 
     nohtml=str 
end function

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网