Reputation: 2693
How to allow splitting only if _x are the latest 2 characters in the string?
Example: hello-world_x.jpg should be splitted and hello_xtra_world.jpg not.
filename.text = imagename.text.split("_x").join("")
Thanks Uli
Upvotes: 1
Views: 953
Reputation: 82594
You can use RegExp:
filename.text = imagename.text.split(/_x$/).join("")
This will work better:
imagename.text.replace(/(.+)_x(\.[a-z]+)/i, "$1$2");
Upvotes: 3
Reputation: 2065
I think it's better practice to use replace
in combination with the RegExp @Joe-Tuskan suggested.
filename.text = imagename.text.replace(/_x$/, "");
Upvotes: 3