I'm looking for a way to trim a specific sequence of characters from the right and left side of a string in Javascript. It would be ideal if it could be done in a case-insensitive manner.
I do not wish to use jQuery or another library (i.e., I'm hoping for a pure javascript solution, maybe regex?)
For example:
var str = "This is a test. This is a test."
// yields: " is a test. This is a test."
str.trimPhrase('this')
// yields: This is a test. This is a test
str.trimPhrase('.')
// yields: This is a test. This is a test.
str.trimPhrase('is')
// yields: just a single space (the space that was between the sentences).
str.trimPhrase('This is a test.')