I need to do some bulk replacement with Javascript. For my specific problem, let's assume I need to replace a specific substring. I need to change every occurrence of "blue" to "green."
So, I have two ways to do it:
var foo = pegaTexto(); // imagine que isso retorna uma string qualquer;
foo = foo.replace("azul", "verde");
Or:
var foo = pegaTexto();
foo = foo.replace(new RegExp("azul"), "verde");
In my view, the only practical use of a regular expression would be to specify a flag (to say for example if the search should be global), but in my case I am omitting the flags from the expression constructor.
I have a question, however, regarding performance in these two different ways.
Does using regular expression have any impact on performance?
How can I measure this?