Replacing filename with a Regex in JavaScript
问题 I need to replace a button using a Regex in JavaScript and was wondering how to do this. I know how to grab the src of the button, but I need to take the filename and either add some text "-next" or remove "-next", based on two options that can be toggled. Here are the two different file names: /images/button.png /images/button-next.png Any help would be greatly appreciated. 回答1: To insert a -next before the final dot, you could do result = subject.replace(/(?=\.[^.]+$)/g, "-next"); To remove