Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { private static String getUnclosedTagWithSubstring(String text) { if (text.length() == 0) { return ""; } else if (text.matches("^.*(<[a-zA-Z]*>)$")) { return text; } else if (text.matches("^.*(</[a-zA-Z]*>)$")) { return ""; } else { return getUnclosedTagWithSubstring(text.substring(0, text.length() - 1)); } } }