Check file for email addresses and extract them
Using Java, I need to figure out a way to check if a file has any email addresses in it and then display the email addresses. Doe开发者_如何转开发s any one know how to do this?
Regular Expressions FTW
The code that'll do this is outlined here:
Pattern pattern =
Pattern.compile("the regex string");
Matcher matcher =
pattern.matcher("the file");
boolean found = false;
while (matcher.find()) {
System.out.println(match.group());
found = true;
}
Loop as desired, the way I have it now is to stop when it finds the first address.
The regular expression itself can be found here.
If you have to suffer using Java, then your lifestyle and happiness can be improved using the Java Regex Tester.
精彩评论