Java
Java: , 정규식 표현관련
sucun
2021. 2. 8. 00:56
public class RequalarExam {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("문자열 입력: ");
String str = sc.nextLine();
// abc문자 포함
// if(str.matches(".*abc.*")){
// System.out.println("매칭");
// }else{
// System.out.println("비매칭");
// }
// 자바에서는 \w 를 \\w 로 사용해야 함
// 숫자만 3자리 입력
// if(str.matches("[\\d]{3}")){
// System.out.println("매칭");
// }else{
// System.out.println("비매칭");
// }
// 알파벳, 숫자만 5자리 이상
// if(str.matches("[\\w\\d]{5,}")){
// System.out.println("매칭");
// }else{
// System.out.println("비매칭");
// }
// 한글만 3~5 자리
/* if(str.matches("[가-힣]{3,5}")){
System.out.println("매칭");
}else{
System.out.println("비매칭");
}*/
// 아래내용에 부합되는 사항을 구현
// dolsam77@nate.com => 매칭
// 34dolsam77@nate.com => 비매칭
// dolsam77nate.com => 비매칭
// dolsam77@nate.comcom => 비매칭
if(str.matches("^[a-z]{0,16}" + "[0-9]{0,8}"+ "@[a-z]{0,8}"+ "\\.com")){
System.out.println("매칭");
}else{
System.out.println("비매칭");
}
}
}
public class RequalarExam {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("문자열 입력: ");
String str = sc.nextLine();
// abc문자 포함
// if(str.matches(".*abc.*")){
// System.out.println("매칭");
// }else{
// System.out.println("비매칭");
// }
// 자바에서는 \w 를 \\w 로 사용해야 함
// 숫자만 3자리 입력
// if(str.matches("[\\d]{3}")){
// System.out.println("매칭");
// }else{
// System.out.println("비매칭");
// }
// 알파벳, 숫자만 5자리 이상
// if(str.matches("[\\w\\d]{5,}")){
// System.out.println("매칭");
// }else{
// System.out.println("비매칭");
// }
// 한글만 3~5 자리
/* if(str.matches("[가-힣]{3,5}")){
System.out.println("매칭");
}else{
System.out.println("비매칭");
}*/
// 아래내용에 부합되는 사항을 구현
// dolsam77@nate.com => 매칭
// 34dolsam77@nate.com => 비매칭
// dolsam77nate.com => 비매칭
// dolsam77@nate.comcom => 비매칭
if(str.matches("^[a-z]{0,16}" + "[0-9]{0,8}"+ "@[a-z]{0,8}"+ "\\.com")){
System.out.println("매칭");
}else{
System.out.println("비매칭");
}
}
}
반응형