可以做立体图形的网站,现在写博客还是做网站,网站建设的基本流程,wordpress 虚拟主机1. 正则表达式字面量改进
特性#xff1a;在 ES6 中#xff0c;正则表达式字面量允许在字符串中使用斜杠#xff08;/#xff09;作为分隔符。 用法#xff1a;简化正则表达式的书写。
const regex1 /foo/;
const regex2 /foo/g; // 全局搜索2. u 修饰符#xff08;U…1. 正则表达式字面量改进
特性在 ES6 中正则表达式字面量允许在字符串中使用斜杠/作为分隔符。 用法简化正则表达式的书写。
const regex1 /foo/;
const regex2 /foo/g; // 全局搜索2. u 修饰符Unicode
特性u 修饰符允许正则表达式正确处理 Unicode 字符。 用法确保正则表达式在处理多字节字符时表现正确。
const regex /foo/u;
console.log(regex.test(foö)); // 输出false3. y 修饰符Sticky
特性y 修饰符使正则表达式在搜索时“粘”在每个匹配的开始位置。 用法进行连续的匹配搜索。
const text abcabc;
const regex /abc/y;let match;
while ((match regex.exec(text)) ! null) {console.log(Found ${match[0]} at index ${match.index});
}
// 输出
// Found abc at index 0
// Found abc at index 34. 新增的正则表达式方法
特性String.prototype.match(), String.prototype.replace(), String.prototype.search(), 和 String.prototype.split() 现在可以接受正则表达式字面量。 用法直接使用正则表达式进行字符串处理。
const text Hello World;
const regex /Hello/;console.log(text.match(regex)); // 输出[Hello]
console.log(text.replace(regex, Hi)); // 输出Hi World
console.log(text.search(regex)); // 输出0
console.log(text.split(regex)); // 输出[, World]5. flags 属性
特性正则表达式对象现在有一个 flags 属性返回正则表达式的修饰符。 用法获取正则表达式使用的修饰符。
const regex /foo/g;
console.log(regex.flags); // 输出g6. dotAll 模式点字符匹配所有
特性当设置了 s 修饰符dotAll时点字符.可以匹配包括换行符在内的任何字符。 用法进行多行匹配。
const text foo\nbar;
const regex /bar/s; // 使用 dotAll 模式console.log(regex.test(text)); // 输出true7. hasIndices 属性
特性hasIndices 属性用于指示正则表达式是否捕获分组。 用法检查正则表达式是否包含捕获组。
const regex1 /foo/;
const regex2 /foo(bar)/;console.log(regex1.hasIndices); // 输出false
console.log(regex2.hasIndices); // 输出true8. Symbol.match, Symbol.replace, Symbol.search, Symbol.split
特性这些 Symbol 属性允许使用正则表达式进行字符串匹配、替换、搜索和分割。 用法提供一种更灵活的方式来处理字符串。
const text Hello World;
const regex /world/i;console.log(text[Symbol.match](regex)); // 输出[World]
console.log(text[Symbol.replace](regex, there)); // 输出Hello there
console.log(text[Symbol.search](regex)); // 输出4
console.log(text[Symbol.split](regex)); // 输出[Hello , ]