java regex pattern validate html tag

Regular expression html tag pattern


This regular expression refers to a pattern which start with an opening tag “<" , follow by double quotes "string", or single quotes 'string' but does not allow one double quotes (") "string, one single quote (') 'string or a closing tag > without single or double quotes enclosed. At last, end with a closing tag “>”


package com.w3spoint;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexTest {
	private static final String PATTERN = 
	public static void main(String args[]){ 
		List<String> values = new ArrayList<String>();	
		values.add("<input value=> >");
		Pattern pattern = Pattern.compile(PATTERN);
		for (String value : values){
		  Matcher matcher = pattern.matcher(value);
			  System.out.println("Tag "+ value +" is valid");
			  System.out.println("Tag "+ value +" is invalid");


Tag <br> is valid
Tag <input/> is valid
Tag <input value=> > is invalid
Please Share