正则表达式
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>javascript-Regex</title>
</head>
<style type="text/css">
body,html,ul,li{padding: 0;margin: 0;list-style: none}
.warp{max-width: 1200px;width: 80%;margin: auto;}
.demo{display: block;margin-top: 50px;border: #ddd solid 1px;}
</style>
<body>
</body>
<script src='http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js'></script>
<script type="text/javascript">
/* "^The" 开头
"ar$" 结尾
"^abc$" 开头结尾一样
"notice" 包含notice的
"ab*" a后面有0个或者很多个b
"ab+" a后面有1个或者很多个b
"ab?" a后面跟着0个或者1个b
"a?b+$" 结尾有0个或者1个a跟着一个或者几个b
"ab{2}" 一个a后面跟着2个b
"ab{2,}" 一个a后面至少有2个b
"ab{3,5}" 一个a后面跟着3到5个b
"hi|hello" 有hi或者有hello
"(a|b)*c" a,b后面跟着一个c
"." 可以代替任何字符
"a.[0-9]" a后面跟着任意字符和一个数字
"^.{3}$" 任意三个字符
"[ab]" 相当于 "a|b"
"[a-d]" 相当于 "a|b|c|d"
"^[a-zA-Z]" 以字母开头
"[0-9]*%" 后面跟有%的数字
",[a-zA-Z0-9]$" 以逗号后面跟着一个字母或者数字结束
"^[0-9]{1,20}$" 1到20个数字组成
"^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,9}$" 以字母开头,可以加 。或者——的5-10位字符
"^[a-zA-Z]{1,30}$" 校验用户姓名:只能输入1-30个以字母开头的字串
"^(\w){6,20}" \w(字母,数字或下划线)
*/
var test="abc999";
var zheng="^[a-z]{1,3}$";
var tt=test.match(zheng);
if(tt==null){
console.log("666");
}else{
console.log(tt);
}
</script>
</html>
1.replace 替换字符串
2.test 匹配字符串,返回 true or false
3.match 匹配字符串,返回数组
4.search 返回位置,没有则返回-1
5.exec 该函数通过对指定你的字符串进行一次匹配检测

浙公网安备 33010602011771号