My input string is
String input=" 4313 :F:7222;scott miles:F:7639;Henry Gile:G:3721";
It's a string with semicolon delimiter. It can contain any number of values delimited by semicolon
I want to use Group capture feature in java and capture the below values (i.e : delimited)
4313 :F:7222
scott miles:F:7639
Henry Gile:G:3721
I know I can use split function under Spring class but for some reason I want to use group capture here.
I tried
Matcher myMatcher = Pattern.compile("(.*?);").matcher(input);
while (myMatcher.find()) {
System.out.println("group is " + myMatcher.group());
}
output is
group is 4313 :F:7222;
group is scott miles:F:7639;
but expected output is
group is 4313 :F:7222
group is scott miles:F:7639
group is Henry Gile:G:3721
I am not getting how to capture the last value after last semicolon and also I want to get rid of semicolon as I mentioned in expected outcome.