In JavaScript assume I have a string: “test test hello test test”
I know how to replace the ‘hello’ with ‘byebye’:
replace("hello","byebye");
But what is the best way to add ‘byebye’ right after ‘hello’, so my string will become: “test test hello byebye test test”, using regex?
Thanks.
The best way, would be to use a capturing group. Like this:
Docs on MDN
Demo