import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "href=\"(.+)\">(C#: парсинг HTML кода страницы)<";
final String string = "\n"
+ "<a class=\"question-hyperlink\" href=\"/questions/412931/c-%d0%bf%d0%b0%d1%80%d1%81%d0%b8%d0%bd%d0%b3-html-%d0%ba%d0%be%d0%b4%d0%b0-%d1%81%d1%82%d1%80%d0%b0%d0%bd%d0%b8%d1%86%d1%8b\">другая ссылка</a>\n\n"
+ "<a class=\"question-hyperlink\" href=\"http://ru.stackoverflow.com/questions/412931/c-%D0%BF%D0%B0%D1%80%D1%81%D0%B8%D0%BD%D0%B3-html-%D0%BA%D0%BE%D0%B4%D0%B0-%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D1%8B\">C#: парсинг HTML кода страницы</a>\n\n"
+ "<a class=\"question-hyperlink\" href=\"/questions/412931/c-%d0%bf%d0%b0%d1%80%d1%81%d0%b8%d0%bd%d0%b3-html-%d0%ba%d0%be%d0%b4%d0%b0-%d1%81%d1%82%d1%80%d0%b0%d0%bd%d0%b8%d1%86%d1%8b\">C#: парсинг HTML кода страницы</a>\n\n"
+ "<a class=\"question-hyperlink\" href=\"/questions/412931/c-%d0%bf%d0%b0%d1%80%d1%81%d0%b8%d0%bd%d0%b3-html-%d0%ba%d0%be%d0%b4%d0%b0-%d1%81%d1%82%d1%80%d0%b0%d0%bd%d0%b8%d1%86%d1%8b\">другая ссылка</a>\n\n\n"
+ "<a class=\"question-hyperlink\" href=\"/questions/412931/c-%d0%bf%d0%b0%d1%80%d1%81%d0%b8%d0%bd%d0%b3-html-%d0%ba%d0%be%d0%b4%d0%b0-%d1%81%d1%82%d1%80%d0%b0%d0%bd%d0%b8%d1%86%d1%8b\">другая ссылка</a>";
final Pattern pattern = Pattern.compile(regex);
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