我想從完整的字串中提取這部分:
<a href=\"https://example.com/members/will/\">Will</a>
完整字串:
"<a href=\"https://example.com/members/will/\">Will</a> posted an update in the group <a href=\"https://example.com/groups/testing/\">Testing</a>"
另一個例子
<a href=\"https://example.com/members/longerName/\">longerName</a>
完整字串:
"<a href=\"https://example.com/members/longerName/\">longerName</a> posted an update in the group <a href=\"https://example.com/groups/testing/\">Testing</a>"
請有任何幫助
uj5u.com熱心網友回復:
從我的頭頂來看,這可能會奏效。
正則運算式
<a\b[^>]*>(.*?)</a>
鏢
final myString = "<a href=\"https://example.com/members/will/\">Will</a> bla bla bla";
final regexp = RegExp(r'<a\b[^>]*>(.*?)</a>');
// final match = regexp.firstMatch(myString);
// final link = match.group(0);
Iterable matches = regexp.allMatches(myString);
matches.forEach((match) {
print(myString.substring(match.start, match.end));
});
uj5u.com熱心網友回復:
這可以作業:
String str = "<a href=\"https://example.com/members/will/\">Will</a> posted an update in the group <a
href=\"https://example.com/groups/testing/\">Testing</a>";
String result = str.split("</a>")[0] "</a>";
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/470227.html
上一篇:我想在顫動的兩個陣列值之間相乘