-1
I would like to replace multiple words with a single for example:
This is what I tried, here only the first occurrence is changed
var replaceGN = "Gênesis"
var str = "Este é o livro de GEN, Gn é o primeiro livro da bíblia, leia Gen.";
var matchesGN = str.match( /GN|GEN|GEN\./g );
r = str.replace(/[matchesGN]/g, replaceGN)
alert(r);
given an index
1-GE
1-GEN
1-GEN.
1-GÊN
1-GENESIS
1-GÊNESIS
1-GÉNESIS
1-GN
1-GN.
2-OUTRO
2-OUT
2-OUT.
2-OU.
given value of each index
1=Gênesis
2=Outro
String
"This is the book of Genesis, Genesis is the first book of the Bible This is Out. book, O. interesting book"
Expected result
"This is the book of Genesis, Genesis is the first book of the Bible This is Another book, Another interesting book"
@Augustovasques put what I had been trying unsuccessfully.
– Miguel Silva
"Este é o livro de GEN, Gn é o primeiro livro da bíblia, leia Gen.".replace(/\b(GN|GEN)\b/ig, "Gênesis")
– Valdeir Psr
Wow, very simple and efficient, Thanks @Valdeirpsr
– Miguel Silva