I'm currently repeating the task like below:
var parts = "<h1>I</h1><p>am a cow;</p>cows say moo. MOOOOO."
.split(/(\bmoo+\b)/gi);
for (var i = 1; i < parts.length; i += 2) {
parts[i] = renderToString(<MyComponent key={i}>{parts[i]}</MyComponent>);
}
var anotherParts = parts.split(/(\bcow+\b)/gi);
for (var i = 1; i < anotherParts.length; i += 2) {
anotherParts[i] = renderToString(<MyOtherComponent key={i}>
{anotherParts[i]}
</MyOtherComponent>)
}
return anotherParts
Is this possible to do the above task at once? I'm looking for most feasible way to do that because I wanted to replace more and more multiple strings.
replace()method with global optioni += 2- what is that for?