巷尾的酒吧

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  64 Posts :: 0 Stories :: 5 Comments :: 0 Trackbacks
匹配数字和字母组合,数字和字母至少出现一次,只匹配1a,1q1,a1,a1a,1q2q2ws,w1w2e3r4r之类的,不匹配11,aa,a,1,"",这种的。
package com.abin.lee.servlet.regex;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MyRegex {
public static boolean StringResult(String str)throws Exception{
String regex="^(\\d+[a-z]+[0-9a-z]*)|([a-z]+\\d[0-9a-z]*)$";
// String regex="^(\\d+[a-z]{1}[0-9a-zA-Z]*)|([a-z]+\\d[0-9a-zA-Z]*)$";
Pattern pattern=Pattern.compile(regex);
Matcher matcher=pattern.matcher(str);
boolean flag=matcher.matches();
return flag;
}
public static void main(String[] args) throws Exception{
String str="aa1as12ds3232ds2d22";
boolean result=StringResult(str);
System.out.println("result="+result);
}
}
posted on 2012-10-18 23:17 abing 阅读(1066) 评论(1)  编辑  收藏 所属分类: regex

Feedback

# 23434 2013-12-30 09:58 4324
的撒旦  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: