木子屋 Dnawo's BLOG

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

👤 dnawo 📅 2007-07-16 👁 4759 👍 0 💬 0 🔄 本站原创
在修改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)

暂无评论。

计算题
评论需审核通过后显示
← 上一篇 深度解析Windows最令人迷惑的两大进程 下一篇 → 教你一招万能的黑掉所有网站的方法