<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script>
var oToMatch = "This is your Life";
var reLife = /Life/ ;
alert(oToMatch.replace(reLife,"Girl"));
//等价于,用函数写
var sResult = oToMatch.replace(reLife,function(ss){
return "Boy";
});
alert(sResult);
var sToMatch = "a bat, a Cat, a fAt, a FAt";
var reg = /[bcf]at/gi;//g表示所有的,i表示不区分大小写
var arrayMatch = sToMatch.match(reg);
//for(var s in arrayMatch){
// alert(arrayMatch[s]);
//}
//-----负向类-----不以b或者c开头滴--//
var sToMatch2 = "a bat, a Cat, a fAt, a FAt";
var regb = /[^bc]at/gi;
var arrayMatch2 = sToMatch2.match(regb);
//for(var s in arrayMatch2){
//alert(arrayMatch2[0]);
//}
//-----范围类-------//
var sToMatch3 = "num1, num2, num3,num4,num5,num6";
var regb3 = /num[1-4]/gi;
var arrayMatch3 = sToMatch3.match(regb3);//num1, num2, num3,num4
//------组合类---------------//
//比如想匹配从a-m的字母以及从1-4的数字,以及一个换行符: var regb4 =[a-m1-4\n];
//-----预定义类-------//
// 数字:\d 非数字:\D 空白字符:\s 非空白字符:\S
//--------------量词--------------------//
//出现零次或一次:"?" =={0,1} 出现零次或多次:"*" {0,} 出现一次或多次:"+" {1,}
//eg:要配置bread,read或red: var regb5 = /b?ea?d/
function isValidEmail(sText){
var isEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;
return isEmail.test(sText);
}
</script>
<BODY>
</BODY>
</HTML>
posted on 2008-05-19 22:58
bcterry 阅读(79)
评论(0) 编辑 收藏