by SimonSelg · 10y ago · 0 comments
const target = 'Get on the Road' const result = target.replace(/road/i, 'bus')
str-replace uses regex internally but abstracts it in a fluent interface for legibility purposes at the cost of not optimizing prematurely. Regex is definitely the solution if one want to make more complex replaces or need to care about micro-optimizations like the use of regex without an additional function call (which imho in 90% of the cases is irrelevant).