Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class SplitString {
- public static void main(String[] args) {
- String s = "ABCD";
- s += "12345678901234567890123456789012345678901234567890";
- s += "12345678901234567890123456789012345678901234567890";
- s += "12345678901234567890123456789012345678901234567890";
- s += "12345678901234567890123456789012345678901234567890";
- s += "12345678901234567890123456789012345678901234567890";
- s += "EFGH1234";
- s += "ABCD";
- s += "12345678901234567890123456789012345678901234567890";
- s += "12345678901234567890123456789012345678901234567890";
- s += "12345678901234567890123456789012345678901234567890";
- s += "12345678901234567890123456789012345678901234567890";
- s += "12345678901234567890123456789012345678901234567890";
- System.out.println("Before:");
- System.out.println(s);
- s = s.replaceAll("ABCD\\d{250}", "\n$0\n");
- System.out.println("After:");
- System.out.println(s);
- Scanner in = new Scanner(s);
- Pattern p = Pattern.compile("ABCD\\d{9}(\\d{16})(\\d{16})");
- while (in.hasNextLine()) {
- Matcher m = p.matcher(in.nextLine());
- if (m.find()) {
- System.out.print("1: ");
- System.out.println(m.group(1));
- System.out.print("2: ");
- System.out.println(m.group(2));
- }
- }
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement