letter.letter.year大于2018@uts.edu.co
j.g.2019@uts.edu.co
0.j.g@cloudmail.com.co
a-zA-Z + .?a-zA-Z + .?2-9 (?!18 $) 1-9?+$\@ uts (.)edu (.)co
a-zA-Z + .?co
private void btn_validarActionPerformed(java.awt.event.ActionEvent evt) {
String w_correo = caja_correo.getText();
Pattern p_correo1 = Pattern.compile("^[a-zA-Z]+[.]?[a-zA-Z]+[ .]?[2-9][0-9](?!18$)[1-9][1-9]?+$\\@uts([.])edu([\\.])co$");
Matcher m_correo1 = p_correo1.matcher(w_correo);
Pattern p_correo2 = Pattern.compile("^\\b([0]|20[0-1][0-8]|2019)\\b+[.]?[a-zA-Z]+[.]?[a-zA-Z]+\\@ [a-zA-Z] ([.])com([\\.])co$");
Matcher m_correo2 = p_correo2.matcher(w_correo);
if (m_correo1.matches()) {
String validacion = "";
validacion = validacion + "Direccion de correo electrónico correcta<br/>";
correcto.setForeground(Color.GREEN);
}
else {
String validacion = "";
if (!m_correo1.matches()) {
validacion= validacion + "Direccion de correo electrónico incorrecta<br/>";
incorrecto.setBackground(Color.RED);
}
}
if (m_correo2.matches()) {
String validacion = "";
validacion = validacion + "Direccion de correo electrónico correcta<br/>";
correcto.setForeground(Color.GREEN);
}
else {String validacion = "";
if (!m_correo2.matches()) {
validacion= validacion + "Direccion de correo electrónico incorrecta<br/>";
incorrecto.setBackground(Color.RED);
}
}
} 发布于 2019-04-14 13:36:36
下面的正则表达式与您描述的模式相匹配:"letter.letter.year大于2018@uts.edu.co“。
([a-zA-Z]\.){2}([2-9][1-9][0-9]{2}|20([2-9][0-9]|19))@uts\.edu\.co
([a-zA-Z]\.){2} matches any letter followed by a period two times.
([2-9][1-9][0-9]{2}|20([2-9][0-9]|19)) matches the year 2019 or greater
@uts\.edu\.co matches @uts.edu.co literally.在这里尝试一下:https://regex101.com/r/hNIMRL/1
发布于 2019-04-14 14:23:20
尝试以下正则表达式:"(?:a-zA-Z.){2}(0-9{4})\@uts.edu.co“
我已经对你的示例电子邮件进行了测试。使用年份的捕获组,可以验证年份是否大于2018年。RegEx将仅匹配遵循您的Letter.Letter.Four数字Year@uts.edu.co模式的电子邮件
下面是我用来测试regEx的.java:
import java.util.regex.Pattern;公共类MainApp {
public static void main(String[] args) {
// reg ex to use: (?:[a-zA-Z]\.){2}([0-9]{4})\@uts.edu.co
String[] email = {"j.g.2018@uts.edu.co","s.c.2019@uts.edu.co","t.t.2020@gmail.com"};
String regExPattern = "(?:[a-zA-Z]\\.){2}([0-9]{4})\\@uts.edu.co";
Pattern p = Pattern.compile( regExPattern );
for(String x : email){
Matcher m = p.matcher( x );
boolean b = m.matches();
if(b){
int year = Integer.parseInt(m.group(1));
if(year > 2018){
System.out.println(x + " is valid");
}
else{
System.out.println(x + " is not valid");
}
}
else{
System.out.println(x + " is not valid");
}
}
}}从我的控制台登录:
j.g.2018@uts.edu.co无效
s.c.2019@uts.edu.co有效
t.t.2020@gmail.com无效
干杯!
发布于 2019-04-14 16:39:10
对于这类大于2018@uts.edu.co的电子邮件letter.letter.year,如j.g.2019@uts.edu.co,您可以使用:
^[a-zA-Z]\.[a-zA-Z]\.(?:2019|20[2-9][0-9]|2[1-9][0-9]{2}|[3-9][0-9]{3})@uts\.edu\.co$^ string[a-zA-Z]\.[a-zA-Z]\.匹配的开始2次字符a-z,后跟一个字符串匹配范围greater than 2018@uts\.edu\.co Match @uts.edu.co$ End of string在Java中
String regex = "^[a-zA-Z]\\.[a-zA-Z]\\.(?:2019|20[2-9][0-9]|2[1-9][0-9]{2}|[3-9][0-9]{3})@uts\\.edu\\.co$";对于这种类型的电子邮件0-2018.letter.etter@*.com.co,比如0.j.g@cloudmail.com.co,你可以使用:
^(?:2018|201[0-7]|200[0-9]|1[0-9]{1,3}|[0-9]{1,3})\.[a-zA-Z]\.[a-zA-Z]@\w+(?:\.\w+)*\.com\.co$string
(?:2018|201[0-7]|200[0-9]|1[0-9]{1,3}|[0-9]{1,2}) Range的开始^ 0 to 2018\.[a-zA-Z]\.[a-zA-Z]匹配2次字符匹配,后跟字符匹配@,重复字符a-z@\w+(?:\.\w+)* chars\.com\.co @,重复字符char,然后重复字符.com.co$ 1+ 0+点和字符串1+ 的结束
在Java中
String regex = "^(?:2018|201[0-7]|200[0-9]|1[0-9]{1,3}|[0-9]{1,3})\\.[a-zA-Z]\\.[a-zA-Z]@\\w+(?:\\.\\w+)*\\.com\\.co$";https://stackoverflow.com/questions/55672162
复制相似问题