现在的位置: 首页 > 综合 > 正文

正则表达式之反向引用

2012年09月14日 ⁄ 综合 ⁄ 共 342字 ⁄ 字号 评论关闭

示例1:

	public static void main(String[] args) {
		String s="99-3933";
		boolean b=Pattern.matches("([\\d])\\1[-]([3])\\1\\2{2}", s);
		System.out.println(b);
	}

反向引用,匹配重复的数字

([\d])====>\1

([3])====>\2

示例2:

public class test {
	public static void main(String[] args) {
		String s="99-393399-3933";
		boolean b=Pattern.matches("(([\\d])\\2[-]([3])\\2\\3{2})\\1", s);
		System.out.println(b);
	}
}

抱歉!评论已关闭.