Hello Everyone!, My question is quite simple But a bit confusing:
How do I replace a specific 100% match word in a string in Javascript/NodeJS?
For an example, Let's say I have this string:
var String = "123 Hi my name is ftk [1] > | I like to play [] games [1] , I have 111 games on my PC."
As you can see above, The string has multiple symbols and multiple numbers as well, Now I want to replace every [1] to be empty or replaced by another word, So the output will be:
String = "123 Hi my name is ftk > | I like to play [] games , I have 111 games on my PC."
Notice that neither
[]
nor
1
has been gone, But only <[1]>, I just want to replace any word that matches my word 100% if that makes sense.
Thanks soo much in advance!
What I have tried:
I have tried 2 ways:
1- Using .relpace():
var String2 = String.replace("[1]", "");
But this one removes everything included in the string, It'll remove 1, [, and ], And I only want to remove every word that looks exactly like the given one
2- Using global variable to remove all repeated one, Which is what I want, But same thing, It behaves like 1.
var String2 = String.replace(/[1]/g, "");
var String2 = String.replace(/"[1]"/g, "");