Let say we need to split the following
String into an array of four elements.
We want to ignore the escaped comas and produce the following array.
Messages Hello,World Hobbies Java,Programming
String.split(",") will produces an array of six elements, which is not what we want. Regular expressions provide the look around assertion which allows us to ignore the comas which are preceded by the escape character
String s = "Messages,Hello\,World,Hobbies,Java\,Programming"; System.out.println(Arrays.toString(s.split("(?<!\\\\),")));