import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(\\d{2})\\/(\\d{2})\\/(\\d{2})\\s+(\\d{2}):(\\d{2})\\s+([\\d]+)\\s+([\\d]+|)\\s+(<I>|)(EXT|)([\\w]+|)(\\s+|)((\\d{1})'(\\d{2})|)(\\s+|)((\\d{2}):(\\d{2})'(\\d{2})\\s+(.*) |)";
final String string = "01/02/16 09:37 1142 01 2286542PPPPPP9131874263 00:00'24 \n"
+ "01/02/16 09:37 1204 48 2181 00:01'33 \n"
+ "01/02/16 09:37 1221 33 <I>3342 0'00 00:01'25 TR \n"
+ "01/02/16 09:38 1232 02 2286542PPPPPP9082035024 00:00'12 \n"
+ "01/02/16 09:39 1711 EXT1132 \n"
+ "01/02/16 09:39 1232 01 2286542PPPPPP9082035024 00:00'02 \n"
+ "01/02/16 09:39 5910 11 <I> 0'01 00:00'37 D0 \n"
+ "01/02/16 09:39 1602 EXT1611 \n"
+ "01/02/16 09:39 1332 EXT1204 \n"
+ "01/02/16 09:40 1222 34 <I>3933 0'02 00:00'14 \n"
+ "01/02/16 09:40 1232 EXT1393 \n"
+ "01/02/16 09:41 1262 EXT1154 \n"
+ "03/02/16 16:11 2181 EXT2421 \n"
+ "03/02/16 16:13 2181 05 89509600795 00:00'47 \n"
+ "03/02/16 16:13 2314 24 1242 00:00'08 \n"
+ "03/02/16 15:07 2162 05 <I> 0'00 00:00'15 TR \n"
+ "03/02/16 15:09 2004 05 <I> 0'05 00:00'50 \n"
+ "03/02/16 15:11 2004 05 <I> 0'38 00:00'00 NA \n"
+ "03/02/16 15:12 2004 06 <I> 0'11 00:00'26 \n"
+ "03/02/16 15:16 2004 05 <I> 0'04 00:01'02 \n"
+ "03/02/16 15:18 2181 17 <I>1396 0'04 00:12'23 \n"
+ "03/02/16 15:20 2151 07 89020100016 00:00'17 \n"
+ "03/02/16 15:21 2004 24 1132 00:00'24 TR \n"
+ "03/02/16 15:21 2004 05 <I> 0'05 00:01'37 \n"
+ "03/02/16 15:21 2151 07 89509668727 00:00'22 \n"
+ "03/02/16 15:23 2151 05 89020116661 00:00'20 \n"
+ "01/02/16 09:31 5910 11 <I> 0'01 00:00'24 D0 \n"
+ "01/02/16 09:31 1221 33 <I>4351 0'00 00:04'55 TR \n"
+ "01/02/16 09:31 5910 03 <I>89831514875 0'01 00:00'14 D0 \n"
+ "01/02/16 09:32 1204 11 <I> 0'00 00:00'45 TR \n"
+ "01/02/16 09:32 1125 03 <I>89831514875 0'00 00:00'16 TR \n"
+ "01/02/16 09:32 5910 03 <I>89831514875 0'01 00:00'13 D0 \n"
+ "01/02/16 09:32 5910 09 <I> 0'01 00:00'10 D0 ";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html