I am trying to write a function to replace any standalone set of matching characters. For example:
var myarray = ["this is", "this is iss"]
var my2array = []
var regex = '/bis/b'
for (const i of myarray) {
var x = i.replace(regex, "")
my2array.push(x)
}
console.log(my2array)
My desired output would be:
["this", "this iss"]
I got this working in Python, but am not able to translate it properly to Javascript. Currently my output is just the array values [0] and [1] (not sure why Javascript is doing that).
Anyway, my question is, how can I achieve the desired output using regex in Javascript?
bis, why do you expect it to replace anything?var regex = /\bis\b/you have mistyped slashes.