Advertisement
Guest User

Regexp test

a guest
Jan 13th, 2012
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. import java.util.regex.*;
  2.  
  3. public class test
  4. {
  5.  
  6.     public static void main( String[] args )
  7.     {
  8.         String input = "20120113_1234_27_500_(33)";
  9.                     // yyyyMMdd_HHmm_ss_unitCode_(status)
  10.         String regex = "(\\d{4})(\\d{2})(\\d{2})_(\\d{2})(\\d{2})_(\\d{2})_([^_]+)_\\((.+)\\)";
  11.         Pattern p = Pattern.compile(regex);
  12.         Matcher m = p.matcher(input);
  13.  
  14.         System.out.println( "Input = " + input );
  15.         System.out.println( "regex = " + regex );
  16.  
  17.         if (m.matches())
  18.         {
  19.             int nGroups = m.groupCount();
  20.             for (int pos = 1; pos <= nGroups; pos++)
  21.             {
  22.                 System.out.println("Group " + pos + ": " + m.group(pos) );
  23.             }
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement