Advertisement
cd62131

SplitString

Jul 6th, 2014
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.33 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4.  
  5. public class SplitString {
  6.     public static void main(String[] args) {
  7.         String s = "ABCD";
  8.         s += "12345678901234567890123456789012345678901234567890";
  9.         s += "12345678901234567890123456789012345678901234567890";
  10.         s += "12345678901234567890123456789012345678901234567890";
  11.         s += "12345678901234567890123456789012345678901234567890";
  12.         s += "12345678901234567890123456789012345678901234567890";
  13.         s += "EFGH1234";
  14.         s += "ABCD";
  15.         s += "12345678901234567890123456789012345678901234567890";
  16.         s += "12345678901234567890123456789012345678901234567890";
  17.         s += "12345678901234567890123456789012345678901234567890";
  18.         s += "12345678901234567890123456789012345678901234567890";
  19.         s += "12345678901234567890123456789012345678901234567890";
  20.         System.out.println("Before:");
  21.         System.out.println(s);
  22.         s = s.replaceAll("ABCD\\d{250}", "\n$0\n");
  23.         System.out.println("After:");
  24.         System.out.println(s);
  25.         Scanner in = new Scanner(s);
  26.         Pattern p = Pattern.compile("ABCD\\d{9}(\\d{16})(\\d{16})");
  27.         while (in.hasNextLine()) {
  28.             Matcher m = p.matcher(in.nextLine());
  29.             if (m.find()) {
  30.                 System.out.print("1: ");
  31.                 System.out.println(m.group(1));
  32.                 System.out.print("2: ");
  33.                 System.out.println(m.group(2));
  34.             }
  35.         }
  36.         in.close();
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement