2009-09-01

java Struts Validator EscapeSpecialChar

Pattern.compile("[^a-zA-Z0-9 ]"):
This method compiles a regular expression "[^a-zA-Z0-9 ]" which does
not detects a to z, A to Z and 0 to 9 characters, means it detects all
special symbols or characters.


import java.util.regex.*;
import java.io.*;

public class EscapeSpecialChar{
public static void main(String[] args) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter string to find special characters: ");
String string = in.readLine();
Pattern pattern = Pattern.compile("[^a-zA-Z0-9]");
Matcher matcher = pattern.matcher(string);
String str = matcher.replaceAll("F");
System.out.print(str);
}
}

0 留言: