String对象方法match/matchAll/normalize/padEnd/padStart
match:通过正则表达式,将匹配出的内容存入数组并返回
var str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
var regexp = /[A-E]/gi;
var matches_array = str.match(regexp);
console.log(matches_array);
matchAll:通过正则表达式,将匹配出的内容存入数组,同时还会存储对应匹配的情况,最后返回
const regexp = /t(e)(st(\d?))/g;
const str = 'test1test2';
const array = [...str.matchAll(regexp)];
console.log(array[0]);
console.log(array[1]);
normalize:定的一种Unicode正规形式将当前字符串正规化
const name1 = '\u0041\u006d\u00e9\u006c\u0069\u0065';
const name2 = '\u0041\u006d\u0065\u0301\u006c\u0069\u0065';
console.log(name1, name2);
console.log(name1 === name2);
console.log(name1.length === name2.length);
const str1 = name1.normalize('NFD');
console.log(str1);
padStart:指定对应输出宽度,如果字符串小于该宽度,则用指定的字符从头部进行填充
let str = "hello world";
console.log(str.padStart(30, "*"));
padEnd:指定对应输出宽度,如果字符串小于该宽度,则用指定的字符从尾部进行填充
let str = "hello world";
console.log(str.padEnd(30, '*'));