import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\d\\d\\/\\d\\/\\d\\d\\d\\d";
final String string = "=! VANHOLLANO DUMAI!\n\n"
+ " !12/5/2018 ! !07:26!\n"
+ "!Jl. Jend. Sudirman No. 183 Dumai \n"
+ "Hp. 08116252883 \n"
+ "IDN !\n"
+ "! !\n"
+ "!vbdumsdr01 ! !Novita !\n"
+ "!Cust. Name..: ! ! !\n"
+ "! !\n"
+ "!---------------------------------!\n"
+ "! 1! !SHOPPING BAG SMALL! ! 0!\n"
+ "! 2! !PALMIER ! ! 7,400!\n"
+ "! 1! !ROTI SISIR KELAPA ! ! 15,800!\n"
+ "! ! ! !\n"
+ "!---------------------------------!\n"
+ "!Subtotal ! ! 23,200!\n"
+ "!Total Discount ! ! 0!\n"
+ "!PB1 ! ! 2,320!\n"
+ "!Total ! ! 25,520!\n\n"
+ "!Cash ! ! 50,500!\n\n"
+ "!Change back (Cash) ! ! 24,980!\n"
+ "!=================================!\n\n"
+ " ! PERIKSA KEMBALI!\n"
+ "!struk belanja dan uang kembalian !\n"
+ " !anda. Komplain hanya bisa!\n"
+ "!dilakukan saat transaksi di kasir!\n\n"
+ " !Customer Service!\n"
+ " !SMS: 08117541984!\n"
+ " !PIN BB: 2B4DCF32!\n\n"
+ " ! FOLLOW US!\n"
+ "!ig : vanhollanobakery_jnpgroup !\n"
+ " !www.jnp-g.com!\n"
+ " !Thank You!";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
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