java - What's a good regex to remove extraneous characters from the end of a string? -
i'm looking regex remove characters @ end of string aren't needed, may present earlier in string (which expected , good).
here's example should resolve "carver house - kitchen"
carver house - kitchen( carver house - kitchen[ carver house - kitchen - ( carver house - kitchen :
here's example should resolve "carver house : (night)[n1] - kitchen"
carver house : (night)[n1] - kitchen( carver house : (night)[n1] - kitchen[ carver house : (night)[n1] - kitchen - ( carver house : (night)[n1] - kitchen :
so basically, last letter or number should found , else whacked off.
also, i'm not looking big messy method goes character character find last alphanumeric. should possible in line or 2 of code.
thanks
you can use regex \w+$
find non-word-characters @ end of string , replace those.
string s = "carver house : (night)[n1] - kitchen - ("; s = s.replaceall("\\w+$", ""); system.out.println(s);
result carver house : (night)[n1] - kitchen
Comments
Post a Comment