I have the following String that I need to parse. I am looking for the Board State for each Slot number.
Some lines...
SLOT 2 (RP/LC 2): Random Text
MAIN:
PCA:
... More text
Board State is Val
... More text
Some lines...
SLOT 3 (RP/LC 3): Random Text
MAIN:
PCA:
... More text
Board State is Val2
... More text
subslot 0/9/0
Currently I have this.
String regex = "(^SLOT\\s*\\d+).*\\s*.*\\s*.*\\s*.*\\s*.*\\s*.*\\s*.*\\s*.*\\s*.*\\s*.*\\s*.*\\s*.*\\s*.*\\s*.*\\s*.*\\s*.*\\s*.*\\s*.*\\s*(Board.*)";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(commandOutput);
while(matcher.find()) {
//Do Something
}
I am hard coding the number of lines it needs to skip but I don’t like this and it’s bad programming.
Is it possible to do something like
regex = "(^SLOT\\s*\\d+)(.*\\s*)+(Board.*)"; //This obviously doesn't work. Find slot, then skip one or more lines until it finds Board. I am using \\s instead of \\r\\n because \\s skips tabs as well.
Edit: As to precisely what I want from the regex. Put SLOT # in a group and the Board State is Val in another group for all the SLOTS.
I would suggest using this simplified regex for your problem like this:
OUTPUT: