请哪位大虾,写下这个表达式
   1231123|[email protected]
  以上只能输入数字或者是email格式

解决方案 »

  1.   


    import java.util.regex.Pattern;public class Pattern2 { public static void main(String[] args) {
    String reg = "^(\\d+|\\w[-.\\w]*\\@[-a-z0-9]+(?:\\.[-a-z0-9]+)*\\.(?:com|edu|info|gov|int|mil|net|org|name|museum|coop|aero|[a-z][a-z]))$";

    System.out.println(Pattern.matches(reg, "123444"));
    System.out.println(Pattern.matches(reg, "[email protected]"));
    System.out.println(Pattern.matches(reg, "1234aa44"));
    System.out.println(Pattern.matches(reg, "[email protected]"));
    }}
      

  2.   

    Pattern p = Pattern.compile("(^[1-9]\\d*$|^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$)");