I have been using this regex to validate email addresses. Files found not to have valid Email addresses on a certain line are deleted:
FileInputStream fsdel = new FileInputStream("C:/Folder/" + filefinal[o]);
BufferedReader brdel = new BufferedReader(new InputStreamReader(fsdel));
for (int j = 0; j < 4; j++) {
brdel.readLine();
}
String email = brdel.readLine();
String mine = email.trim();
String lineIwant = mine.substring(0, 32).trim();
// System.out.println("EMAIL ID: " + lineIwant);
String emailreg = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
Boolean b = lineIwant.matches(emailreg);
if (b.toString() == "false") {
System.out.println(filedel[o]);
fsdel.close();
//brdel.close();
filedel[o].delete();
}
This piece of code has been working fine until one file appeared with an email Id :
textsam.textsample@somedomain.co.uk
The file was deleted as one that does not have a valid email address. Can someone please help me on how to include the above email address as a valid one?