1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| Matcher matcher1=null,matcher2=null,matcher3 = null;
String matchIp=null,matchNom=null,matchDescription=null;
// String regexp="\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b\\";
String regexpIP="\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b";
String regexpNom="\\s\\b([a-zA-Z0-9_ ]+\\s?)\\b";
String regexpDescription="#.*";
Pattern SEPARATOR_PATTERN1 = Pattern.compile(regexpIP);
Pattern SEPARATOR_PATTERN2 = Pattern.compile(regexpNom);
Pattern SEPARATOR_PATTERN3 = Pattern.compile(regexpDescription);
String Ligne[] = null;
try {
Ligne=LireLigne.LireString("hosts");
} catch (IOException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
// if (matcher != null)matcher.reset(Ligne[index]);
matcher1 = SEPARATOR_PATTERN1.matcher(Ligne[index]);
matcher2 = SEPARATOR_PATTERN2.matcher(Ligne[index]);
matcher3 = SEPARATOR_PATTERN3.matcher(Ligne[index]);
// Using find
while(matcher1.find()) {
matchIp = Ligne[index].substring(matcher1.start(),matcher1.end());
System.out.println("debut =>"+matcher1.start()+" match _"+matchIp+"_ fin =>"+matcher1.end());
}
if(matcher2.find()) {
matchNom = Ligne[index].substring(matcher2.start(),matcher2.end()).replaceFirst("\\s", "");
System.out.println("debut =>"+matcher2.start()+" match _"+matchNom+"_ fin =>"+matcher2.end());
}
if(matcher3.find()) {
matchDescription = Ligne[index].substring(matcher3.start(),matcher3.end()).replaceFirst("#\\s", "");
System.out.println("debut =>"+matcher3.start()+" match _"+matchDescription+"_ fin =>"+matcher3.end());
} |
Partager