how can I modify this regular expression so that it distinguishes between latin and russian letters in links and emails
At the moment my program looks like this:
let final = text;
const divElement = document.createElement('div');
// eslint-disable-next-line max-len
const linkRegExp = /\b(((http(s)?:\/\/)([\w-]{1,32}(\.|\:)[\w-]{1,32}))|([\w-]{1,32}(\@)[\w-]{1,32}(\.)[\w-]{1,32})|([\w-]{1,32}(\.)[A-Za-z]{1,32}))\b/gi;
function replacer(url) {
if (url.match(/\S+@\S+\.\S+/ig)) {
const email = document.createElement('a');
email.innerHTML = url;
email.href = `mailto:${url}`;
email.setAttribute('class', 'email');
return `${email.outerHTML}`;
}
const link = document.createElement('span');
link.innerHTML = url;
link.setAttribute('class', 'link');
link.setAttribute('style', 'color: blue; cursor: pointer');
return `${link.outerHTML}`;
}
final = final.replace(RegExp(linkRegExp), replacer);
Unfortunately, replacing [\w-] with [\wА-Яа-я-] did not give positive results
Via Active questions tagged javascript - Stack Overflow https://ift.tt/TV4c29I
Comments
Post a Comment