I need to replace text using Javascript. It’s a little different than the other ones I’ve seen on S.O. because the text that needs to be added in is an incrementing integer.
For example: Replace the string: “John Mary Ellen Josh Adam” with “John1 Mary2 Ellen3 Josh4 Adam5”
Use a callback replacer:
EDIT: Noticed that won’t add a number after “Adam”. That can be fixed just by adding:
at the end of the code.
EDIT2: Or all-in-one: