因此,对于我的作业,我需要检查输入的格式是否正确,并且没有其他信息。我发现了有关使用正则表达式,模式和compile
函数的信息,但是我只需要正则表达式格式的代码。我在网上查了一下东西
退出
1. For phone : ( ### ) - ### - ###
2. Name : Abc Def
3. Email : abc.def@ghi.com
Name: [A-Z][a-z]+[ ][A-Z][a-z]+
Phone : ([0-9][0-9][0-9])-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]
Email : [a-z]([a-z])*(.[a-z]+)*@[a-z]+.(a-z)+
对于电子邮件:
String emailRegex = "\"^[_A-Za-z0-9-]+(\\\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\\\.[A-Za-z0-9]+)*(\\\\.[A-Za-z]{2,})$\"";
//this is just some random code that I dont even understand
Pattern pattern = Pattern.compile(emailRegex);
if (pattern.matcher(email).matches()) {
System.out.println(email);
}else {
//Further processing
}
所以我只需要弄清楚如何将其转换为正则表达式代码,即可将其与输入字符串进行比较*