I was browsing and from stackoverflow for this, but I had no luck.
The line I want to work with is "xbananay", where "x" and "y" can be any random combination of letters or numbers of any length. So my line might just be "qrstbananag", but it could also be "abcbanana12345".
I want to use and use the javascript replacement function to replace everything, BUT "banana". I already have some regular expression that a banana can find, but the replacement function, as expected, will replace what I am looking for when I want to find everything else. Example:
var fullString = "qrstbananag"
var strippedBanana = fullString.replace(/(?:banana)/g, '');
I also have a regex expression that ALMOST receives from me what I am looking for, but includes all the characters in the string "banana". Another example:
var fullString2 = "abcbanana12345"
var strippedBanana = fullString2.replace(/[^(?:banana)]/g, '');
How can I accomplish this using only the replace function? Thanks in advance.
source
share