import java.util.regex.*;
import java.io.*;
public class SpecialCharacters
{
public static void main( String[] args ) throws IOException
{
String string = "ashzxcvbnmasdfghjklopiuytrewqASHWINI00675%%%%";
Pattern pattern = Pattern.compile( "[^a-zA-Z0-9*]" );
Matcher matcher = pattern.matcher( string );
System.out.println(matcher.find());
String str = matcher.replaceAll( "F" );
System.out.print( str );
}
}
where [^a-zA-Z0-9*] Any character except a to z, A-Z , 0 to 9 or *
If it will find other then these character the matcher.find() return true else false
matcher.replaceAll( "F" ) will replace all the occurrence of other characters with F
Thanks ...
ReplyDeleteNice to follow the code and explanation ...