我必须解析以下示例输出。要求是后面不应该有文本,Fabric management FPC state:
即它应该是空\s
的。下一部分有点棘手,我被困在那里。所以每个FPC
人都有一个或多个PFE
,每个FPE
人都有一个或多个SIB
。每个 有四种可能的状态SIB
。他们是Plane Enabled, Link Error, Desination Error and Plane Disabled
。我应该使用正则表达式解析它并跟踪每个FPC, PFE and SIB
. 我不知道如何'linked'
在正则表达式中有一个组。
Fabric management FPC state:
FPC #0
PFE #0
SIB #0
Plane enabled
SIB #1
Link Error
PFE #1
SIB #0
Destination Error
SIB #1
Plane Disabled
SIB #2
Plane enabled
FPC #1
PFE #1
SIB #0
Plane enabled
到目前为止我所拥有的是
public void parseFPCS(String commandOutput) {
regex = "FPC state:(\\s*)(FPC\\s*#?\\d+)\\s*(PFE\\s*#\\d+)\\s*(SIB\\s*#\\d+)\\s*(\\w*\\s*\\w*)";
pattern = Pattern.compile(regex, patternFlag);
matcher = pattern.matcher(commandOutput);
while(matcher.find()) {
String empty = matcher.group(1);
Boolean isEmpty = empty.trim().isEmpty();
if(isEmpty) {
System.out.println("Link Empty");
System.out.println(matcher.group(2));
System.out.println(matcher.group(3));
System.out.println(matcher.group(4));
System.out.println(matcher.group(5));
//Right now I am just printing it out to see the outcome.
}
}
The current outcome is
Link Empty
FPC #0
PFE #0
SIB #0
Plane enabled //This is expected.