I have a String which I want to parse. The String is like this :-
00:0qwe8.0 donald controller duck [02009&123@##]: Some more sring here Model number 420 Family [Super-cool] [15b31013^^@#][15b:31013]
Notice the last Square bracket has a : colon in it. and the character before Some More is also a colon. I want to capture all the characters between them.
Currently I am parsing it with the following regex in two steps.Here is the java code.
class JavaReg{
public static void main(String[] args){
String str = "00:0qwe8.0 donald controller duck [02009&123@##]: Some more sring here Model number 420 Family [Super-cool] [15b31013^^@#][15b:31013]";
String[] strArr = str.split("\\[.*?\\]\\:\\s");
String[] str12 = strArr[1].split("\\[\\w*?\\:.*");
for(String strinj : strArr)
System.out.println(strinj);
System.out.println(str12[0]);
}
}
The following is the result of the above exercise.
00:0qwe8.0 donald controller duck
Some more sring here Model number 420 Family [Super-cool] [15b31013^^@#][15b:31013]
Some more sring here Model number 420 Family [Super-cool] [15b31013^^@#]
The last string is what I want. It starts capturing from the colon : and goes on to capture till the Square bracket which has a colon.
The question is can I use capturing groups in regex to capture it in one shot. How to do that in Java?