eriezelagera

Using regular expression

Jul 30th, 2013
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. package Test;
  2.  
  3. import java.io.*;
  4.  
  5. public class StringContains {
  6.    
  7.     private static String input;
  8.  
  9.     public static void main( String args[] ) throws IOException {
  10.        
  11.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  12.        
  13.         while ( !(input = br.readLine()).isEmpty() ) {
  14.             System.out.println("Alpha only = " + input.replaceAll("\\d", "").replaceAll("\\W", "").replaceAll("\\s", ""));
  15.             System.out.println("Numberic only = " + input.replaceAll("\\D", ""));
  16.             System.out.println("Symbols only = " + input.replaceAll("\\w", ""));
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment