How to Split a String with Escaped Delimiters?

Java 8Object Oriented ProgrammingProgramming

The split(String regex) method of the String class splits this string around matches of the given regular expression.

Example

Live Demo

public class Sample{
   public static void main(String args[]){
      String s = "|A|BB||CCC|||";
      String[] words = s.split("\|");
      for (String string : words) {
         System.out.println(string);
      }
   }
}

Output

A
BB
CCC
raja
Updated on 26-Feb-2020 09:42:44

Advertisements