문제

I'm getting a compilation error when I use this regular expression inside the String class's matches() method. Anyone know what I'm doing wrong here? Thanks

String email = "this@that.com";
System.out.println(email.matches("^(.+@.+\.\\w{2,4})$"));
도움이 되었습니까?

해결책

escape period . with two backslashes \\. valid escape sequences supported in java are \b \t \n \f \r \" \' \\

System.out.println(email.matches("^(.+@.+\\.\\w{2,4})$"));

OR:

Enclose it within \\Q and \\E

\\Q.\\E
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top