I'm a little stuck at a regular expression. Consider following code:
String regFlagMulti = "^(\\[([\\w=]*?)\\])*?$";
String flagMulti = "[TestFlag=1000][TestFlagSecond=1000]";
Matcher mFlagMulti = Pattern.compile(regFlagMulti).matcher(flagMulti);
if(mFlagMulti.matches()){
for(int i = 0; i <= mFlagMulti.groupCount(); i++){
System.out.println(mFlagMulti.group(i));
}
}else{
System.out.println("MultiFlag didn't match!");
}
What I want is a regular pattern that gives me the text inside the [ ]; each one in a group of the resulting Matcher object.
Important: I don't know how many [ ] expressions are inside the input string!
For the code above it outputs:
[TestFlag=1000][TestFlagSecond=1000]
[TestFlagSecond=1000]
TestFlagSecond=1000
I can't get the regular Pattern to work. Anyone an idea?