我有一个满足条件的正则表达式,但开头允许使用连字符。一开始如何限制。我想在开头使用连字符限制的正则表达式,因为它允许我需要一些其他字符。
/^[A-Z0-9-._%+]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i;
预先感谢
答案 0 :(得分:0)
这似乎对我有用
public class QuickyTest{
static String[] testVectors = { "alaskjf",
"o-kay@example.com",
"-dash@x.AA",
"dash-@y.ZZ" };
public static void main( String[] args ) {
Pattern pattern = Pattern.compile( "(?i:[A-Z0-9._%+]+|[A-Z0-9._%+]+[A-Z0-9._%+-]+[A-Z0-9._%+]+@([A-Z0-9-]+.)+[A-Z]{2,4})" );
for( String test : testVectors ) {
Matcher match = pattern.matcher( test );
System.out.println( test + " : " + match.matches() );
}
}
}