import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "<(?!\\/*strong\\W|\\/*h1\\W|\\/*input\\W|\\/*b\\W).*?>";
final String string = "<form action=\"#\" method=\"post\">\n"
+ " <div>\n"
+ " <label for=\"name\">Text Input:</label>\n"
+ " <input type=\"text\" name=\"name\" id=\"name\" value=\"\" tabindex=\"1\" />\n"
+ " </div>\n\n"
+ " <div>\n"
+ " <h4>Radio Button Choice</h4>\n\n"
+ " <label for=\"radio-choice-1\">Choice 1</label>\n"
+ " <input type=\"radio\" name=\"radio-choice-1\" id=\"radio-choice-1\" tabindex=\"2\" value=\"choice-1\" />\n\n"
+ " <label for=\"radio-choice-2\">Choice 2</label>\n"
+ " <input type=\"radio\" name=\"radio-choice-2\" id=\"radio-choice-2\" tabindex=\"3\" value=\"choice-2\" />\n"
+ " </div>\n\n"
+ " <div>\n"
+ " <label for=\"select-choice\">Select Dropdown Choice:</label>\n"
+ " <select name=\"select-choice\" id=\"select-choice\">\n"
+ " <option value=\"Choice 1\">Choice 1</option>\n"
+ " <option value=\"Choice 2\">Choice 2</option>\n"
+ " <option value=\"Choice 3\">Choice 3</option>\n"
+ " </select>\n"
+ " </div>\n\n"
+ " <div>\n"
+ " <label for=\"textarea\">Textarea:</label>\n"
+ " <textarea cols=\"40\" rows=\"8\" name=\"textarea\" id=\"textarea\"></textarea>\n"
+ " </div>\n\n"
+ " <div>\n"
+ " <label for=\"checkbox\">Checkbox:</label>\n"
+ " <input type=\"checkbox\" name=\"checkbox\" id=\"checkbox\" />\n"
+ " </div>\n\n"
+ " <div>\n"
+ " <input type=\"submit\" value=\"Submit\" />\n"
+ " </div>\n"
+ "</form>";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html