0

I need a regular expression for the multiline string as below

Customer:
            VA000347
            VA000347
            Ashu Corp
            Others
            Enterprise

                Mumbai
                5
                Mumbai
                Maharashtra
                232323
                India

        :customer

I want to extract the later part i.e. "customer" from the multiline string using regular expression in java and I can match the first part(Customer) literally.

Any help is greatly appreciated.

Kyborek
  • 1,519
  • 11
  • 20
user1356042
  • 395
  • 2
  • 6
  • 23

1 Answers1

0
    String text = "Customer:\n"
            + "            VA000347\n"
            + "            VA000347\n"
            + "            Ashu Corp\n"
            + "            Others\n"
            + "            Enterprise\n"
            + "\n"
            + "                Mumbai\n"
            + "                5\n"
            + "                Mumbai\n"
            + "                Maharashtra\n"
            + "                232323\n"
            + "                India\n"
            + "\n"
            + "        :customer";
    Pattern pattern = Pattern.compile("(?<=Customer:\n)(?s)(.*)(?=:customer)");
    Matcher matcher = pattern.matcher(text);
    matcher.find();
    System.out.println(matcher.group(1));