호그래머

자바 문자열 한글 체크하기 정규화 방법1(Java regex) 23.06.14 본문

Java

자바 문자열 한글 체크하기 정규화 방법1(Java regex) 23.06.14

호그래머 2023. 6. 14. 00:57
728x90

1. 자바 문자열 한글체크 하기 - regex

import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class tistory_java_230614 {

	public static void main(String[] args) {
		String text = "가나AA다1234";
        String regex = "[\\p{IsHangul}]+";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(text);
        
        if (matcher.find()) {
            System.out.println("문자열에 한글 있음.");
        } else {
            System.out.println("문자열에 한글 없음.");
        }
	}
}

결과

문자열에 한글 있음.

 

1. 자바에서 쉽게 정규화를 이용하여 문자열 속에 한글이 있는지 체크 할 수 있다.

728x90
Comments