Programming

[정규표현식] - include one character or more at least

kimxavi 2020. 3. 26. 20:42
반응형

상황

String 에 문자 집합 중 어느 하나라도 포함되어 있는지 확인이 필요할 때

 

해결

// 알파벳이 하나라도 있는지 확인하는 예제 코드

String str1 = "a030982309!";
String str2 = "0030982309!";

String regex = ".*[a-zA-Z]+.*";

System.out.println(str1.matches(regex)); // true
System.out.println(str2.matches(regex)); // false

 

응용

응용할 때는, a-zA-Z 부분을 원하는 것으로 해주면 된다

반응형