1

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

2 Answers 2

3

I think it's better practice to use replace in combination with the RegExp @Joe-Tuskan suggested.

filename.text = imagename.text.replace(/_x$/, "");
Sign up to request clarification or add additional context in comments.

Comments

3

You can use RegExp:

filename.text = imagename.text.split(/_x$/).join("")


Edit

This will work better:

imagename.text.replace(/(.+)_x(\.[a-z]+)/i, "$1$2");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.