
Java의 String 클래스의 replaceAll 메소드는 대소문자를 구분하여 문자열을 대체합니다. 대소문자를 구분하지 않고 문자열을 대체하려면 toLowerCase() 또는 toUpperCase() 메소드를 사용하여 대소문자를 일치시키는 방법이 있습니다.
예를 들어, "Hello"와 "hello"를 대체하려면 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
java
String str = "Hello, hello";
String replaceValue = "world";
String result = str.replaceAll("hello", replaceValue.toLowerCase());
System.out.println(result); // Hello, world
또는
#hostingforum.kr
java
String str = "Hello, hello";
String replaceValue = "world";
String result = str.replaceAll("(?i)hello", replaceValue);
System.out.println(result); // Hello, world
(?i) 패턴은 대소문자를 구분하지 않고 매치를 수행하도록 지정합니다.
2025-08-05 15:26