fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. String ifIdentifier = "/interfaces/interface-xr/interface[interface-name='GigabitEthernet0/0/0/1']";
  14. String neighborId = null;
  15. String extractedString = (null != ifIdentifier) ? (ifIdentifier.substring(ifIdentifier.lastIndexOf("[")+1, ifIdentifier.lastIndexOf("]"))) : null;
  16. String[] splitter = (null != extractedString) ? (extractedString.split("=")) : null;
  17. neighborId = (splitter.length >= 1) ? (splitter[1].replaceAll("'", "")) : null;
  18. System.out.print(neighborId);
  19. }
  20. }
Success #stdin #stdout 0.08s 55580KB
stdin
Standard input is empty
stdout
GigabitEthernet0/0/0/1