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

时间:2014-12-04 20:04:22   收藏:0   阅读:409

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

地址抛上: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,布布扣

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

原文:http://blog.csdn.net/huolang_vip/article/details/41727741

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!