1
다음 샘플 출력을 구문 분석해야합니다. 요구 사항은 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.
그런 식으로 접근하는 것이 더 쉬울 것입니다. – theking963