Remove all non-alphanumeric character from string using regex

Write a program to remove all non-alphanumeric characters from a string.

Example:

Input:  " Become code $#expert using % beingCode       expert"
Output: "BecomecodeexpertusingbeingCodeexpert"

 Approach:

 Java:


import java.util.regex.*;

public class BeingCodeExpert {
    
    public static void main(String[] args) {

        String inputString = " Become code @#expert using ^& beingCode       expert";

        String outputString = inputString.replaceAll("[^A-Za-z0-9]", "");

        System.out.println(outputString);

    }
}


No comments:

Post a Comment