fork download
  1. class Ideone {
  2. public static void main (String[] args) {
  3. String[] input = {
  4. "HDR^A1^A20220106^ATYPE^AXXX^AJAPAN^AUNIFORM^AHELP^AEXAMPLE^A",
  5. "HDR^A1^A20220106^ATYPE^AXXX"};
  6. int n = 6;
  7. for (int i = 0; i < input.length; i++) {
  8. String str = input[i].replaceAll("(.*?(\\^A.*?){" + n + "})\\^A.*|.*", "$1");
  9. System.out.println("Input " + i + ": " + str);
  10. }
  11. }
  12. }
Success #stdin #stdout 0.13s 52968KB
stdin
Standard input is empty
stdout
Input 0: HDR^A1^A20220106^ATYPE^AXXX^AJAPAN^AUNIFORM
Input 1: