Skip to content
Advertisement

regex replace just the last charater of a string

This should be an easy one and I couldn’t find it anywhere. How do I replace just the last character of a string with a char from an array?

JavaScript

Advertisement

Answer

$ matches the end of a string, . matches any character

JavaScript

But you should probably use string functions for this:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement