fix replace all with special characters
This commit is contained in:
committed by
mayswind
parent
263bf08f34
commit
d0a5c93e49
+6
-1
@@ -155,7 +155,12 @@ export function getObjectOwnFieldCount(object) {
|
||||
}
|
||||
|
||||
export function replaceAll(value, originalValue, targetValue) {
|
||||
return value.replaceAll(new RegExp(originalValue, 'g'), targetValue);
|
||||
// Escape special characters in originalValue to safely use it in a regex pattern.
|
||||
// This ensures that characters like . (dot), * (asterisk), +, ?, etc. are treated literally,
|
||||
// rather than as special regex symbols.
|
||||
const escapedOriginalValue = originalValue.replace(/([.*+?^=!:${}()|\-/\\])/g, '\\$1');
|
||||
|
||||
return value.replaceAll(new RegExp(escapedOriginalValue, 'g'), targetValue);
|
||||
}
|
||||
|
||||
export function removeAll(value, originalValue) {
|
||||
|
||||
Reference in New Issue
Block a user