正则表达式匹配HTML单双标签

时间:2014-12-04 20:06:41   收藏:0   阅读:159

//很好的正则表达式教程

地址抛上:http://deerchao.net/tutorials/regex/regex.htm

package com.huowolf;

import java.util.Scanner;

public class Demo8 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = null;

		while(true) {
			s=sc.nextLine();
			System.out.println(IsHTML(s));
		}
	}
	
	public static boolean IsHTML(String s) {
		String reg = "<(\\w+?>).+?</\\1||<[^>]+?(\\s\\w+?=.+?)*/>";
		return s.matches(reg);
	}
}
bubuko.com,布布扣

自己码的,如果不对请指出来。

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!