Here is an attempt to explain a bit clearer with code--
str = 'testfoostringfoo';
var regex = /foo$/;
if (str.match(regex) == true) {
str.trim(regex);
return str; //expecting 'testfoostring'
}
I'm looking for the simplest way to accomplish this using only javascript, though jQuery is available. Thanks for your time. :]
Fully functioning code with the help from @Kobi-
var str = 'testfoostringfoo';
var regex = /f00$/;
if (str.match(regex)) {
str = str.replace(regex, '');
return str; //returns 'testfoostring' when the regex exists in str
}