I would like to need the java code for extracting html tags.
Here is a java example that extract a tag from a line of HTML using the Pattern and Matcher classes.
import java.util.regex.Matcher; import java.util.regex.Pattern; public class ExtractContentFromHTMLTag { public static void main(String[] args) { String stringToSearch = "<p>Hello <h1>Welcome To Roseindia</h1> ...</p>"; Pattern p = Pattern.compile("<h1>(\\S+)</h1>"); Matcher m = p.matcher(stringToSearch); if (m.find()){ String codeGroup = m.group(1); System.out.format("'%s'\n", codeGroup); } } }
Modify the above code.
import java.util.regex.Matcher; import java.util.regex.Pattern; public class ExtractContentFromHTMLTag { public static void main(String[] args) { String stringToSearch = "<p>Hello <h1>WelcomeToRoseindia</h1> ..</p>"; Pattern p = Pattern.compile("<h1>(\\S+)</h1>"); Matcher m = p.matcher(stringToSearch); if (m.find()) { String codeGroup = m.group(1); System.out.format("'%s'\n", codeGroup); } } }
Ads