I try extracting interface name (in this case FastEthernet0/0) from a regex matching statement. It works when there is only one expression in the pattern, but if 4 expressions are specified in a pattern, separated with |, the output is not what i m expecting. how to modify the code to return 5 times with FastEthernet0/0? There are 5 matches in config. I also tried using matcher.group(2) with almost the same result.
public class ProcessConfig
{
public static void main(String[] args) throws IOException
{
try(
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
)
{
String[] lines=new String[1000];
int i=0;
Pattern pattern=Pattern.compile("(.*snmp-server trap-source\\s)(.+)|(.*ip tacacs source-interface\\s)(.+)|(.*logging source-interface\\s)(.+)|(.*sccp local\\s)(.+)");
Matcher matcher;
while(!(lines[i]=br.readLine()).equals("end"))
{
matcher=pattern.matcher(lines[i]);
if(matcher.matches())
{
System.out.println(matcher.replaceAll("$2"));
}
i++;
}
}
}
}
Thank you
Aucun commentaire:
Enregistrer un commentaire