aa[code]aabb[/code],将[code][/code]间的aa替换为cc

在修改PJBlog时需要一个功能:要求能将aa[code]aabb[/code]字符串[code][/code]之间的aa替换为cc,[code][/code]之外的仍保留原样。想了很久都没解决,上蓝色理想和CSDN上寻求帮助,问题最终才得以解决。下边将代码贴出来和大家共享:

一、蓝色理想misshjn的Javascript解决法

var string = "aa[code]aabb[/code]";
Response.write(string.replace(/\[code\](.*?)\[\/code\]/g,function($1){return $1.replace(/aa/g,"cc")}));

二、CSDN技术社区hookee的VBScript解决法

Dim str,temp
str = "aa[code]aabb[/code]"
Set regEx = New RegExp
regEx.Pattern = "\[code\](.*?)\[\/code\]"
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(str)
For Each Match In Matches
  temp = Replace(Match.Value,"aa","cc")
  str = Replace(str, Match.Value, temp)
Next
Response.write str

在此再次向他们表示感谢!

评论: 0 | 引用: 0 | 查看次数: 4281
发表评论
登录后再发表评论!