var regex = new RegExp('xyz', 'i');
// 等价于
var regex = /xyz/i;
var regex = new RegExp(/xyz/i); // 等价于 var regex = /xyz/i;
// Uncaught TypeError: Cannot supply flags when constructing one RegExp from another var regex = new RegExp(/xyz/, 'i');
console.log(new RegExp(/abc/ig, 'i').flags);//i
//ES5的source属性返回正则表达式的正文 /abc/ig.source//"abc" // ES6的flags属性返回正则表达式的修饰符 /abc/ig.flags//'gi'
String.prototype.match 调用 RegExp.prototype[Symbol.match] String.prototype.replace 调用 RegExp.prototype[Symbol.replace] String.prototype.search 调用 RegExp.prototype[Symbol.search] String.prototype.split 调用 RegExp.prototype[Symbol.split]
/^\uD83D/u.test('\uD83D\uDC2A') // false
/^\uD83D/.test('\uD83D\uDC2A') // true
var text = "𠮷" ; console.log(text.length); // 2 console.log(/^.$/.test(text));//false console.log(/^.$/u.test(text)); //true
/\u{61}/.test('a') // false
/\u{61}/u.test('a') // true
/\u{20BB7}/u.test('𠮷') // true
/a{2}/.test('aa') // true
/a{2}/u.test('aa') // true
/𠮷{2}/.test('𠮷𠮷') // false
/𠮷{2}/u.test('𠮷𠮷') // true
/^\S$/.test('𠮷') // false
/^\S$/u.test('𠮷') // true
function codePointLength(text) {
var result = text.match(/[\s\S]/gu);
return result ? result.length : 0;
}
var s = '𠮷𠮷';
console.log(s.length); // 4
console.log(codePointLength(s)); // 2
function hasRegExpU() {
try {
var pattern = new RegExp(".", "u");
return true;
} catch (ex) {
return false;
}
}
var s = 'aaa_aa_a'; var r1 = /a+/g; var r2 = /a+/y; console.log(r1.exec(s)); // ["aaa"] console.log(r2.exec(s)); // ["aaa"] console.log(r1.exec(s)); // ["aa"] console.log(r2.exec(s)); // null
var s = 'aaa_aa_a'; var r = /a+_/y; console.log(r.exec(s)); // ["aaa_"] console.log(r.exec(s)); // ["aa_"]
'a1a2a3'.match(/a\d/y) // ["a1"] 'a1a2a3'.match(/a\d/gy) // ["a1", "a2", "a3"]
var r = /hello\d/y; r.sticky // true
const TOKEN_Y = /\s*(\+|[0-9]+)\s*/y;
const TOKEN_G = /\s*(\+|[0-9]+)\s*/g;
tokenize(TOKEN_Y, '3 + 4')// [ '3', '+', '4' ]
tokenize(TOKEN_G, '3 + 4')// [ '3', '+', '4' ]
function tokenize(TOKEN_REGEX, str) {
let result = [];
let match;
while (match = TOKEN_REGEX.exec(str)) {
result.push(match[1]);
}
return result;
}
tokenize(TOKEN_Y, '3x + 4') // [ '3' ] tokenize(TOKEN_G, '3x + 4') // [ '3', '+', '4' ]
function hasRegExpY() {
try {
var pattern = new RegExp(".", "y");
return true;
} catch (ex) {
return false;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有