ДОбрый день!
Нужна помощь.
Нужно регулярками вытащить данный из блока <a> </a>
void main() {
final text = """<td><a class="text-dark" href="/myhouse/profile/view/9351311">Текст1</a> </td> <td><a class="text-dark" href="/myhouse/profile/view/9351312">Текст2</a> </td>""";
RegExp exp = new RegExp(r'<a[^>]+href=\"(.*?)\"[^>]*>(.*)?</a>');
Iterable<RegExpMatch> matches = exp.allMatches(text);
// Ожидаю что в matches кол-во будет == 2 (так как два блока с <a ... </a>)
print(matches.toList().length);
matches.toList().forEach((match) {
String data = text.substring(match.start, match.end);
// get code
var re = RegExp(r'(?<=profile/view/)(.*)(?=">)');
var match1 = re.firstMatch(data);
if (match1 != null) print(
match1.group(0));
// get text
var re2 = RegExp(r'(?<=">)(.*)(?=</a>)');
var match2 = re2.firstMatch(data);
if (match2 != null) print(
match2.group(0));
});
}
У меня matches почему-то равен 1, хотя ожидаю 2, так блока с а два.