I have this string that is basically and HTML template for a mention:
<p>lkmlsdkmlskdmflsdk <span class="mention-user" data-initials="AG" data-name="AndréèêÜÄÖß_Güntheräö" id="cxid5024056"><span contenteditable="false"><!----><span class="initials"><!---->AG<!----></span>AndréèêÜÄÖß_Güntheräö<!----><!----></span></span> laksmlaksm lkmalskamlskmaldksml</p>
and I'm using this regex function to remove the HTML of the mention and change for the id of the mention, as a result I should have back this string:
<p>lkmlsdkmlskdmflsdk {mentionuser=cxid5024056} laksmlaksm kmalskamlskmaldksml</p>
as a result I am getting this:
<p>asñald,ñsdl, {mentionuser=cxid5024056}" data-initials="AG" data-name="AndréèêÜÄÖß_Güntheräö laksmlaksm kmalskamlskmaldksml</p>
for this I'm using this function to replace the mention HTML for the mention id format:
Replace mention function
public replaceMention(text: string): string {
if (!text) {
return '';
}
const contentMention = text.split(/(cxid[0-9]{1,8})/);
for (let index = 0; index < contentMention.length; index++) {
if (contentMention[index].match(/<span[^>]*id="/)) {
contentMention[index] = contentMention[index].replace(/<span[^>]*id="/, '');
}
if (contentMention[index].match(/">[^>]*<span[^>]*><[^>]*>(<img[^>]*>)?(<span[^>]*><[^>]*>[^>]*<[^>]*><\/span>)?([^>]*)?(([a-zA-Z\-_.äöüéèêÜÄÖß etc]+)?\s?[a-zA-Z\-_.äöüéèêÜÄÖß etc]+?_[a-zA-Z\-_.äöüéèêÜÄÖß etc]+)([^>]*)?(<[^>]*><[^>]*>)?<\/span>[^>]*<\/span>( )?/)) {
contentMention[index] = contentMention[index].replace(
/">[^>]*<span[^>]*><[^>]*>(<img[^>]*>)?(<span[^>]*><[^>]*>[^>]*<[^>]*><\/span>)?([^>]*)?(([a-zA-Z\-_.äöüéèêÜÄÖß etc]+)?\s?[a-zA-Z\-_.äöüéèêÜÄÖß etc]+?_[a-zA-Z\-_.äöüéèêÜÄÖß etc]+)([^>]*)?(<[^>]*><[^>]*>)?<\/span>[^>]*<\/span>( )?/g,
''
);
}
if (contentMention[index].match(/^(cxid[0-9]{1,8})$/)) {
if (contentMention[index - 1].includes('{mentionuser=') || contentMention[index - 1] === undefined) {
//
} else {
contentMention[index] = `{mentionuser=${contentMention[index]}}`;
}
}
}
let content = contentMention.join('').trim();
console.log('====', content);
return content;
}
In Chrome, Firefox work without any problem but in Edge and Internet Explorer doesn't work. Any idea what could be reason?
lkmlsdkmlskdmflsdk {mentionuser=cxid5024056} laksmlaksm lkmalskamlskmaldksml
` (Test executed in the JS console) – collapsar Jul 01 '19 at 12:44