Inizia subitoInizia gratis

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.

Questo esercizio fa parte del corso

Cleaning Data in Java

Visualizza corso

Istruzioni dell'esercizio

  • 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.

esercizio interattivo pratico

Prova questo esercizio completando questo codice di esempio.

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);
    }
}
Modifica ed esegui il codice