从连字符前的字符中删除元音,并从连字符后面的字符中删除任何数字。
我试过用这个但是我没有正确地使用连字符?
s = replaceAll("[aeiou\-]", "").replaceAll("[-\0-9]", "");
答案 0 :(得分:1)
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);
}
答案 1 :(得分:0)
String str="we-are-students-worker2-45man";
String regex="[aeiouAEIOU]+(?=-)|(?<=-)\\d+";
String newStr=str.replaceAll(regex, "");
System.out.println(newStr);//w-ar-students-worker2-man
//try this