欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JS高级---识别正则表达式是否匹配

程序员文章站 2022-05-18 19:10:10
识别正则表达式是否匹配 console.log(/[a-zA-Z]+/.test("hello")); console.log(/./.test("除了回车换行以为的任意字符"));//true console.log(/.*/.test("0个到多个"));//true console.log(/ ......

识别正则表达式是否匹配

 

    console.log(/[a-za-z]+/.test("hello"));

    console.log(/./.test("除了回车换行以为的任意字符"));//true
    console.log(/.*/.test("0个到多个"));//true
    console.log(/.+/.test("1个到多个"));//true
    console.log(/.?/.test("哈哈"));//true
    console.log(/[0-9]/.test("9527"));//true
    console.log(/[a-z]/.test("what"));//true
    console.log(/[a-z]/.test("are"));//true
    console.log(/[a-za-z]/.test("干啥子"));//false
    console.log(/[0-9a-za-z]/.test("9ebg"));//true
    console.log(/b|(ara)/.test("abra"));//true
    console.log(/[a-z]{2,3}/.test("arfsf"));//true

JS高级---识别正则表达式是否匹配

 

 

 

    console.log(/\d/.test("998")); //true

    console.log(/\d*/.test("998"));

    console.log(/\d+/.test("998"));

    console.log(/\d{0,}/.test("998"));

    console.log(/\d{2,3}/.test("998"));

    console.log(/\d/.test("eat"));

    console.log(/\s/.test("  "));
    console.log(/\s/.test("嘎嘎 "));
    console.log(/\w/.test("_"));
    console.log(/\w/.test("_"));

JS高级---识别正则表达式是否匹配