문제

I am very new to regular expressions. I need to construct a regular expression which if used in the code below would produce a newLine that had only letters (upper and lowercase), numbers, @, -, _ and ..

The following expression does not work: ([^\\w][^@][^-][^_][^\\.]). It replaces some of the letters and not all of the unwanted characters. Why doesn't it work?

String line = in.nextLine();
String newLine = line.replaceAll( "([^\\w][^@][^-][^_][^\\.])", " ");
도움이 되었습니까?

해결책

System.out.println(s.replaceAll("[^a-zA-Z0-9-_@.]",""));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top