Skip to content

Instantly share code, notes, and snippets.

@RobinStamer
Created October 22, 2012 00:59
Show Gist options
  • Select an option

  • Save RobinStamer/3929144 to your computer and use it in GitHub Desktop.

Select an option

Save RobinStamer/3929144 to your computer and use it in GitHub Desktop.
private String strup(String s) {
String strup = new String(s);
if (strup.equals("")) {
return "";
}
while (new Character(strup.charAt(strup.length() - 1)).toString().matches("[`~!@#$%^&*_=|?/,. ]")) {
try {
strup = strup.substring(0, strup.length() - 1);
if (strup.equals("")) {
return "";
}
} catch (Exception e) {
return "";
}
}
Pattern test = Pattern.compile("^(.*?)[`~!@#$%^&*_=|?/,. ]*$");
System.out.println(strup + " vs " + s);
Matcher m = test.matcher(s);
try {
System.out.println(m.groupCount());
System.out.println(m.group(0));
} catch (Exception e) {
e.printStackTrace();
}
try {
System.out.println(m.group(1));
} catch (Exception e) {
e.printStackTrace();
System.out.println(test);
}
return strup.trim();
}
private String strup(String s) {
String strup = new String(s);
if (strup.equals("")) {
return "";
}
while (new Character(strup.charAt(strup.length() - 1)).toString().matches("[`~!@#$%^&*_=|?/,. ]")) {
try {
strup = strup.substring(0, strup.length() - 1);
if (strup.equals("")) {
return "";
}
} catch (Exception e) {
return "";
}
}
return strup.trim();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment