Skip to content

Commit

Permalink
Merge pull request #3 from Collaborne/fix/3373-update
Browse files Browse the repository at this point in the history
Prevent removing keyword from search term
  • Loading branch information
sudhons authored Dec 2, 2024
2 parents e8b175f + 4b04bbb commit 1e941fb
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/search-editor/utils/remove-text.ts
Original file line number Diff line number Diff line change
@@ -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)}$`), '');
}

0 comments on commit 1e941fb

Please sign in to comment.