如何编写Java正则表达式格式以使用pattern.compile

因此,对于我的作业,我需要检查输入的格式是否正确,并且没有其他信息。我发现了有关使用正则表达式,模式和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
}
  

所以我只需要弄清楚如何将其转换为正则表达式代码,即可将其与输入字符串进行比较*

woshicgro 回答:如何编写Java正则表达式格式以使用pattern.compile

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3162578.html

大家都在问