人,
[我正在开发社交媒体应用,我希望人们看到#标签,为此,我想检查字符串是否包含任何#标签,例如:#I_am_nice。
请注意,我不仅要获取#标签标记(#)之后的第一个单词,还希望获取所有#标签。
我想要的:
if (string.contains(Hashtag)) {
print(hashtag);//Hashtag String
} else {
//No Hashtags
}
谢谢,
此Dart代码将满足您的需求:
String text = "Test #first1hashtag test #second2hashtag test.";
RegExp exp = new RegExp(r"\B#\w\w+");
exp.allMatches(text).forEach((match){
print(match.group(0));
});
结果:
#first1hashtag
#second2hashtag