看来,如果您使用正则表达式来分类字符串。这使用正则表达式在@符号前面匹配包含文字点(。)的表达式。我修改了一些来自tutorialspoint的代码以适应电子邮件模式。
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexMatches {
public static void main(String args[]){
// String to be scanned to find the pattern.
String[] emails = {"[email protected]", "[email protected]"};
String pattern = "\\w+[.]\\w+([email protected])";
// Create a Pattern object
Pattern r = Pattern.compile(pattern);
for (int i=0; i<emails.length; i++) {
// Now create matcher object.
String line = emails[i];
System.out.println(line);
Matcher m = r.matcher(line);
if (m.find()) {
System.out.println("MATCH");
} else {
System.out.println("NO MATCH");
}
}
}
}
用正则表达式跳转是一种错误的方法。首先定义具有可量化属性的“支配模式”,然后写出一个问题来提取和比较不同电子邮件之间的属性。 – nhahtdh