从连字符之前的字符中删除元音,并从连字符之后的字符中删除所有数字。
我尝试使用这个,但我没有正确转义连字符?
s = ReplaceAll("[aeiou\-]", "").replaceAll("[-\0-9]", "");
最佳答案
public static void main(String[] args) {
final String toReplace = "magic-8ball";
String splitChar = "-";
String[] split = toReplace.split(splitChar);
String replacedPart1 = split[0].replaceAll("[aeiouAEIOU]", "");
String replacedPart2 = split[1].replaceAll("[0-9]", "");
System.out.println(replacedPart1 + splitChar + replacedPart2);
}
关于java - 从Java中的字符串中删除元音和数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42641695/