开发者

Check file for email addresses and extract them

开发者 https://www.devze.com 2023-03-26 12:35 出处:网络
Using Java, I need to figure out a way to check if a filehas any email addresses in it and then display the email addresses. Doe开发者_如何转开发s any one know how to do this?Regular Expressions FTW

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

Check file for email addresses and extract them


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消