I have a string output that I am trying to capture a list of items from using regex matching. The string is as follows ...
ltm virtual test_vs {
profiles {
foo_bar {
context all
}
baz {
context one
}
qux {
context all
}
}
}
What I want is do is come up with a regex that will match on the whole string and capture foo_bar, baz, and qux out of it, without knowing the values of these captures beforehand. Also, I want it to be flexible in that there can be any number of items to capture; they will just always be in between profiles brackets and each have open and closed brackets themselves with context ANYWORD in between their own brackets. What I have so far is ...
List<String> itemList = new ArrayList<>();
regex = "ltm\\svirtual\\stest_vs\\s\\{\\s*\\n\\s*profiles\\s\\{"+TODO;
pattern = Pattern.compile(regex);
matcher = pattern.matcher(output);
while(matcher.find()) {
itemList.add(matcher.group(1));
}
Just need some help filling in the rest of the regex. Suggestions?
qux { { anything } }?