Communities for your favorite technologies. Explore all Collectives
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
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
I think it's better practice to use replace in combination with the RegExp @Joe-Tuskan suggested.
replace
filename.text = imagename.text.replace(/_x$/, "");
Add a comment
You can use RegExp:
filename.text = imagename.text.split(/_x$/).join("")
This will work better:
imagename.text.replace(/(.+)_x(\.[a-z]+)/i, "$1$2");
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.