js 正则 测试
Posted enych
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js 正则 测试相关的知识,希望对你有一定的参考价值。
var str0 = ‘2013-6-7()‘; var AAAAADD = str0.match(/(d)/g); //11个空字符串 //["2", "0", "1", "3", "6", "7"] var AAAAAD = str0.match(/d/g); //11个空字符串 // ["2", "0", "1", "3", "6", "7"] var AAAAAD1 = str0.match(/d+/g); //["2013", "6", "7"] var AAAAAD2 = str0.match(/(d+)/g); //["2013", "6", "7"] var AAAAAD3 = str0.match(/d+-/g); //["2013-", "6-"] var AAAAAD4 = str0.match(/d+(-)/g); //["2013-", "6-"] var AAAAAD5 = str0.match(/(d+)(-)/g); //["2013-", "6-"]
/// (d+)(-)/g = /d+(-)/g = /d+-/g || /d+/g = /(d+)/g || /d/g = /(d)/g
var data = ‘windows 98 is ok‘; console.log(data); console.log(data.match(/windows (?=d+)/)); // ["windows "] //(?=)会作为匹配校验,但不会出现在匹配结果字符串里面 console.log(data.match(/windows (?:d+)/)); // ["windows 98"] //(?:)会作为匹配校验,并出现在匹配结果字符里面 console.log(data.match(/windows (d+)/)); // ["windows 98", "98"] //先匹配windows 98,在匹配98 var str = "dskf(AAA)_8hjk(CCC)dsk(BBB)"; var reg = /(?:()w+(?:))/; var reg = /(?:()(?:))/; console.log(str.match(/(?:()/));//( console.log(str.match(/w+/)); //dskf console.log(str.match(/(?:))/));//) console.log("10000"); console.log(str.match(/(?:()(?:))/)); //匹配(), console.log(str.match(/(?:()w+(?:))/)); //["(AAA)"] console.log(str.match(/(?:()(w+)(?:))/)); //["(AAA)".AAA]
data = "blang001"; console.log(data); console.log(data.match(/blang/i)); //["blang"] console.log(data.match(/D/ig)); //["b"] 吧不是数字的提取出来 ["b", "l", "a", "n", "g"] console.log(data.match(/lang/i)); // lang 代表非blang 字符串, console.log(data.match(/lang(?:0)/)); var lang = /lang(?:uage)?-([w-]+)/i;
以上是关于js 正则 测试的主要内容,如果未能解决你的问题,请参考以下文章
如何测试文本片段是不是是 Quoted-printable 编码的
通过 Java 正则表达式提取 semver 版本字符串的片段