目前我正在检查以下字符串:
if(parseCommand.contains("vlan1") || parseCommand.contains("Fa0/1i")
|| parseCommand.contains("Fa0/1o") || parseCommand.contains("Fa1/0")
|| parseCommand.contains("Fa1/1") || parseCommand.contains("Fa1/2")
|| parseCommand.contains("Fa1/3") || parseCommand.contains("Fa1/4")
|| parseCommand.contains("Fa1/5") || parseCommand.contains("Fa1/6")
|| parseCommand.contains("Fa1/7") || parseCommand.contains("Fa1/8")
|| parseCommand.contains("Fa1/9") || parseCommand.contains("Fa1/11")
|| parseCommand.contains("Gi0")) {
//do things here
}
但是它可能包含 vlan1 到 vlan4094,我必须检查这些。最简单的方法是什么?
我试过这个只是为了匹配一个 vlan 1-9 后跟 0-3 个数字,但它没有找到任何东西:
if(parseCommand.matches(".*vlan[1-9](\\d){0,3}") || parseCommand.contains("Fa0/1i")
|| parseCommand.contains("Fa0/1o")|| parseCommand.contains("Fa1/0")
|| parseCommand.contains("Fa1/1") || parseCommand.contains("Fa1/2")
|| parseCommand.contains("Fa1/3") || parseCommand.contains("Fa1/4")
|| parseCommand.contains("Fa1/5") || parseCommand.contains("Fa1/6")
|| parseCommand.contains("Fa1/7") || parseCommand.contains("Fa1/8")
|| parseCommand.contains("Fa1/9") || parseCommand.contains("Fa1/11")
|| parseCommand.contains("Gi0")) {
即使我尝试这个也没有发现,为什么?
if(parseCommand.matches(".*vlan.*"
)