diff --git a/src/search-editor/utils/remove-text.ts b/src/search-editor/utils/remove-text.ts index d00339c..e527300 100644 --- a/src/search-editor/utils/remove-text.ts +++ b/src/search-editor/utils/remove-text.ts @@ -1,13 +1,9 @@ const SPECIAL_CHARACTERS_REGEX = /[.*+?^${}()|[\]\\]/g; -const GLOBAL_FLAG = 'g'; function escapeRegExp(text: string): string { return text.replace(SPECIAL_CHARACTERS_REGEX, '\\$&'); } export function removeText(input: string, textToRemove: string): string { - return input.replace( - new RegExp(escapeRegExp(textToRemove?.trim()), GLOBAL_FLAG), - '', - ); + return input.replace(new RegExp(`${escapeRegExp(textToRemove)}$`), ''); }