시작하기무료로 시작하기

Regular expressions

You are managing inventory for an electronics store, and you noticed that some product names have special characters. Regular expressions (regex) allow you to search text for patterns to remove these special characters. Develop a regex pattern to remove any characters that are not lower or upper case letters, or spaces.

이 연습은 강의의 일부입니다

Cleaning Data in Java

강의 보기

연습 안내

  • Complete the regex pattern to exclude lower or upper case letters, and spaces.
  • Remove any character that is not a letter or space from messyProduct.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

public class ProductDataExample {
	public static void main(String[] args) {
    	String messyProduct = "Headphones *(Wireless)*";
        
        // Complete the regex pattern to exclude lower or upper case letters or spaces
        String regex = "[^____]";
        
        // Remove any character that is not a letter or space
        String cleanedProduct = ____.____(regex, "");
        System.out.println(cleanedProduct);
    }
}
코드 편집 및 실행