文章目录
- 86 正则表达式
- 87 字符串和正则相关的方法
- 88 正则表达式语法(1)
- 89 正则表达式语法(2)
- 90 邮件的正则
86 正则表达式
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset = "utf-8">
<script type="text/javascript">var reg = new RegExp("a", "i"); var reg = /a/i;res = /a|b|c/;console.log(res.test("abds"));reg = /[abcdshjk]/;reg = /[a-z]/;reg = /[A-Z]/;reg = /[A-Z]/i; reg = /[A-z]/;reg = /abc|adc|aec/;rsg = /a[bde]c/;rsg = /[^ab]/;rsg = /[^abc]/; rsg = /[^0-9]/;
</script>
<style>
</style>
</head>
<body>
</body>
</html>
87 字符串和正则相关的方法
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset = "utf-8">
<script type="text/javascript">var str = "1a2b3c4d5e6f7";var res = str.split("c");res = str.split(/[A-z]/); str = "hello abc hello abc";res = str.search("abc"); res = str.search(/a[bef]c/);str = "1a2b3c4d5e6f7";res = str.match(/[A-z]/); res = str.match(/[A-z]/g); res = str.match(/[A-z]/gi); res = str.replace(/a/, "@_@");res = str.replace(/a/g, "@_@");res = str.replace(/a/gi, "@_@");res = str.replace(/[a-z]/gi, "@_@");res = str.replace(/[a-z]/gi, "");
</script>
<style>
</style>
</head>
<body>
</body>
</html>
88 正则表达式语法(1)
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset = "utf-8">
<script type="text/javascript">var reg = /aaa/; var reg = /a{3}/; reg.test("aaaa"); reg = /(ab){3}/;reg = /ab{3}c/; reg = /ab{1, 3}c/; reg = /ab{3,}c/; reg = /ab+c/; reg = /ab*c/;reg = /ab?c/;reg = /^a/; reg = /a$/; reg = /^a$/; reg = /^a|a$/; var phoneStr = "123567890123";var phoneReg = /^1[3-9][0-9]{9}$/;console.log(phoneReg.test(phoneStr));
</script>
<style>
</style>
</head>
<body>
</body>
</html>
89 正则表达式语法(2)
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset = "utf-8">
<script type="text/javascript">var reg = /./;console.log(reg.test("b")); var reg = /\./;var reg = /\\/;console.log(reg.test("b.\\")); reg = new RegExp("\.");reg = new RegExp("\\.");reg = /\bchild\b/;reg.test("hello children"); var str = " hello";str = str.replace(/\s/g, "");str = str.replace(/^\s/g, ""); str = str.replace(/^\s*/, ""); str = str.replace(/\s*$/, ""); str = str.replace(/^\s*|\s*$/g, ""); str = str.replace(/^\s+|\s*$/g, "");
</script>
<style>
</style>
</head>
<body>
</body>
</html>
90 邮件的正则
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset = "utf-8">
<script type="text/javascript">var emailReg = /\w{3, }(\.\w+)*@[A-z0-9]+(\.[A-z]{2, 5}){1, 2}/;var email = "abc@abc.com";console.log(emailReg.test(email)); var emailReg = /^\w{3, }(\.\w+)*@[A-z0-9]+(\.[A-z]{2, 5}){1, 2}$/;var email = "abc@abc.com.123";console.log(emailReg.test(email));
</script>
<style>
</style>
</head>
<body>
</body>
</html>