String replaces all special characters at the end

advertisements

Am very poor in regex, so please bear with me.

I have strings LQiW0/QIDAQAB/ and LQiW0/QIDAQAdfB/.

I'm trying to remove the last forward slash.

Tried str= str.replaceAll("\\/","");

I tried replace all but it replaces all forward slashes.. and the thing is, I want to replace if it is at last position


Try following code:

str = str.replaceAll("\\/$", "");

$ means end of line (in this case, end of string).