diff --git a/package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts b/package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts index eebf1fe1ab..b728a0e9c5 100644 --- a/package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts +++ b/package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts @@ -63,7 +63,9 @@ const getMentionUsers = < }, ''); // escape special characters - return mentionUserString.replaceAll(/[.*+?^${}()|[\]\\]/g, '\\$&'); + return mentionUserString.replace(/[.*+?^${}()|[\]\\]/g, function (match) { + return '\\' + match; + }); } return ''; diff --git a/package/src/components/Message/MessageSimple/utils/renderText.tsx b/package/src/components/Message/MessageSimple/utils/renderText.tsx index e533655b62..93b7808ed7 100644 --- a/package/src/components/Message/MessageSimple/utils/renderText.tsx +++ b/package/src/components/Message/MessageSimple/utils/renderText.tsx @@ -226,7 +226,10 @@ export const renderText = < if (userName) { acc += `${acc.length ? '|' : ''}@${userName}`; } - return acc.replaceAll(/[.*+?^${}()|[\]\\]/g, '\\$&'); + + return acc.replace(/[.*+?^${}()|[\]\\]/g, function (match) { + return '\\' + match; + }); }, '') : '';