Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.regex.*;
- public class test
- {
- public static void main( String[] args )
- {
- String input = "20120113_1234_27_500_(33)";
- // yyyyMMdd_HHmm_ss_unitCode_(status)
- String regex = "(\\d{4})(\\d{2})(\\d{2})_(\\d{2})(\\d{2})_(\\d{2})_([^_]+)_\\((.+)\\)";
- Pattern p = Pattern.compile(regex);
- Matcher m = p.matcher(input);
- System.out.println( "Input = " + input );
- System.out.println( "regex = " + regex );
- if (m.matches())
- {
- int nGroups = m.groupCount();
- for (int pos = 1; pos <= nGroups; pos++)
- {
- System.out.println("Group " + pos + ": " + m.group(pos) );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement