Java正则表达式最基本用法

import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class ZhengZeTest
{
	public static void main(String[] args)
	{
		String str = "asd123";
		String regEx =  "[a-z0-9]{6}";
		//regEx = "\\w*";
		//Pattern.CASE_INSENSITIVE是忽略字母的大小写
		Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
		Matcher mat = pat.matcher(str);
		boolean rs = mat.find(); 
		
		System.out.println(rs);		
	}
}

输出结果:

true

你可能感兴趣的:(java,正则表达式)