Im trying to find a solution to remove all instances of a given character from the beginning and end of a string.
Example:
// Trim all double quotes (") from beginnning and end of string
let string = '""and then she said "hello, world" and walked away""';
string = string.trimAll('"',string);
console.log(string); // and then she said "hello, world" and walked away
This function would effectively be to trim
what replaceAll
is to replace
.
My replaceAll solutions is as follows:
String.prototype.replaceAll = function(search, replacement) {
return this.replace(new RegExp(search, 'g'), replacement);
};
This would of course replace all instances of a character in the string, as opposed to just form both ends.
What Regex would be best in this instance?