Your browser does not support the audio element.

java 正则匹配开头和结尾字符串,中间为固定个数的字符

public class TestDemo {

	public static void main(String[] args) {
		//匹配以∈{开头,中间7个字符 ,以}∈结尾的字符串 
		boolean isMatch1 = Pattern.matches("^∈\\{+.{7}\\}∈$", "∈{ddddddd}∈");
		System.out.println(isMatch1);

		boolean isMatch = Pattern.matches("^∞+.{7}∞$", "∞ddddddd∞");

		// .为任意字符串, "^∞+\\d{7}∞$" 表示中间7位字符必须为数字
		Pattern p = Pattern.compile("^∞+.{7}∞$");
		Matcher matcher = p.matcher("∞1212a21∞");
		System.out.println(matcher.find());
	}

}

 

posted @ 2018-11-06 11:36  shoneworn  阅读(20532)  评论(0)    收藏  举报