const str = "s cchh'shchcz'' ";
const regexp = /(sh|sch|ch|cz|yu|ya|yo|zh|''|'|.)/g;
const res = str.match(regexp);
console.log(res);
// ["s", " ", "c", "ch", "h", "'", "sh", "ch", "cz", "''", " "]
function splitStr(str, groups) {
const res = [];
let i = 0;
while (i < str.length) {
const group = groups.find(grp => str.startsWith(grp, i));
if (group === undefined) {
res.push(str[i]);
i += 1;
} else {
res.push(group);
i += group.length;
}
}
return res;
}
const str = "s cchh'shchcz'' ";
const groups = ['sh', 'sch', 'ch', 'cz', 'yu', 'ya', 'yo', 'zh', "''", "'"];
const res = splitStr(str, groups);
console.log(res);
// ["s", " ", "c", "ch", "h", "'", "sh", "ch", "cz", "''", " "]
0
1
close
Name: Elvis
Time: 22:08
close
Name: Kate
Time: 22:09
body
и оказаться. Возможно попробую проверить разные подходы.matches()
не знал, спасибо
str.split('')
наstr.split('').filter(char => (/\d/).test(char))
.