gurpeet singh wrote:please refer the javadocs given at http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#split(java.lang.CharSequence, int)
The input "boo:and:foo", for example, yields the following results with these expressions:
Regex Result
o { "b", "", ":and:f" }
i'm not able to understand the second output i.e. when the regex is o. can somebody explain me how to get the output ?
It's going to split the
string at all instances of "o". It will also remove all trailing instances of "o". So, immediately, your string will become "boo:and:f".
Working from this, at all instances of "o", your string will be split. In cases of consecutive o's, empty string ("") will be used. So your string is split like this:
"boo:and:f" => "b" + "" + ":and:f". All of these pieces will be put into an array like the result quoted above.