首页 > 代码库 > 正则表达式使用

正则表达式使用

 
//判断证件号码是那种类型的(1是15位,2是18位,3是组织机构代码证,0是无效)	private  int panduanCard(String str){		String ps15 = "^\\d{15}$";		String ps18 = "^\\d{17}(\\d|X)$";		//组织机构代码证正则		String zzjg = "^[a-zA-Z0-9]{8}-[a-zA-Z0-9]$";		PatternCompiler orocom = new Perl5Compiler();		try {			Pattern pattern1 = orocom.compile(ps15);			Pattern pattern2 = orocom.compile(ps18);			Pattern zzPattern = orocom.compile(zzjg);			PatternMatcher matcher = new Perl5Matcher();			if (matcher.contains(str, pattern1)) {				return 1;			}else if (matcher.contains(str, pattern2)) {				return 2;			}else if (matcher.contains(str, zzPattern)) {				return 3;			}		} catch (MalformedPatternException e) {			e.printStackTrace();		}		return 0;			}


 

//判断18位是否为身份证	private  boolean isIdCard(String str){		Integer[] rows=new Integer[17];		for (int i = 0; i < rows.length; i++) {			rows[i]=Integer.parseInt(str.charAt(i)+"");		}		//权值		Integer[] quanvalue=http://www.mamicode.com/{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};>


 

//15位升为成18位	private String shengwei(String str){		String newString=str.substring(0, 6)+"19"+str.substring(6, str.length());		Integer[] rows=new Integer[17];		for (int i = 0; i < rows.length; i++) {			rows[i]=Integer.parseInt(newString.charAt(i)+"");		}		//权值		Integer[] quanvalue=http://www.mamicode.com/{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};>


 

正则表达式使用