<script>
function replacestr(str,re)
{
var reg=new RegExp(re,"g")
var nstr;
str = str.replace(reg,function($1,$2){
if($2!="")
{
return "lai";
}
if($1!=""){
return "nihao";
}
});
alert(str)
}
var str="a123测试abc" ;
var re ="([a-z]+)|(\d+)";
replacestr(str,re)
</script>
<script language="javascript" runat=server>
function replacestr1(str,re)
{
var reg=new RegExp(re,"g")
str = str.replace(reg,function($1,$2){
if($2!="") { return "lai";
}
if($1!=""){
return "nihao";
}
});
return str
}
</script>
|