1. <script>
    2. //1.任意字符...
    3. var reg1 = /.../;
    4. console.log(reg1.test('a')); //false
    5. console.log(reg1.test('aaaa')); //true
    6. //2. \w 字母 数字 下划线
    7. var reg2 = /\w\w/;
    8. console.log(reg2.test('_a23'));
    9. console.log(reg2.test('$3'));
    10. //3. \s 任意空白字符 (制表符,回车符,换页符和丨)
    11. var reg3 = /..\s../;
    12. console.log(reg3.test("aa bb"));
    13. console.log(reg3.test('aa bb'));
    14. //4 \d 匹配数字,等同于[0-9]
    15. var reg4 = /\d\d\d\d/;
    16. console.log(reg4.test('9999'));
    17. //5 \D 匹配非数字,等同于\[^0-9]
    18. var reg5 = /\d\D\d/
    19. console.log(reg5.test("hjsafsgjtuytue"));
    20. console.log(reg5.test('4s4'));
    21. //6. | 或匹配
    22. var reg6 = /abc|xyz/;
    23. console.log(reg6.test('dagdayurtsabcfyaifuysxyz'));
    24. //7. [xyz] 表示包含xyz里面的任意一个,相当于x|y|z
    25. var reg7 = /[abc]/;
    26. console.log(reg7.test('a'));//true
    27. console.log(reg7.test('iimooijoi'));//false
    28. // [a-zA-Z] 匹配所偶有的大小写字母 [0-9]相当于\d
    29. //8. [^x] 匹配除“x”之外的所有字符,其中‘x’可以为任意字符
    30. var reg8 = /[^s]/;
    31. console.log(reg8.test('dsadafafa'));//true
    32. console.log(reg8.test('sssssss'));//false
    33. //9.[^xyz]
    34. var reg9 = /[^abc]/;
    35. console.log(reg9.test('a'));//false
    36. console.log(reg9.test('ooimoioihoi'));//true
    37. //10. ^ 匹配字符串的开始
    38. var reg10=/^1\d\d\d\d\d\d\d\d\d\d$/; //11个数字
    39. console.log(reg10.test('13822222222'));
    40. console.log(reg10.test('24353456436573'));
    41. //11. $ 匹配字符串的结束
    42. //12. \ 转义字符
    43. var reg12=/\.com/;
    44. console.log(reg12.test('acom'));
    45. console.log(reg12.test('fafahfgf.com'));
    46. //13. ? 重复出现零次或一次
    47. var reg13=/^https?/;
    48. console.log(reg13.test('http:ihfaifhaifhakfahj'));
    49. console.log(reg13.test('https://dafasfasfafa'));
    50. //14. + 重复出现一次或多次
    51. var reg14=/a+/;
    52. console.log(reg14.test('hfkjsfahfha'));
    53. console.log(reg14.test('ohkookhokooi'));
    54. //15. * 重复出现零次或多次
    55. var reg15=/^https?.*/;
    56. console.log(reg15.test('http:fhajysfte'));
    57. //16. {n} 重复出现n次
    58. var reg16=/^1\d{10}$/;
    59. console.log(reg16.test('12'));
    60. //17. {n,} 至少重复出现n次
    61. var reg17=/^1\d{10,}/
    62. //18.{m,n} 重复出现m到n次,其中m<n
    63. var reg=/\d{m,n}/
    64. </script>