string - 如何找出字符串中以#开头的单词

标签 string flutter dart

我想找出所有以#开头的单词。

例如=这是一个#tag

我想创建这个(#tag)可点击并将其颜色更改为蓝色。 请多多指教!

Text("This is a #tag"),

最佳答案

使用 RegEx 只需两行即可获得所需的结果:

List<String> extractHashtags(String text) {
  Iterable<Match> matches = RegExp(r"\B(\#[a-zA-Z]+\b)").allMatches(text);
  return matches.map((m) => m[0]).toList();
}

关于string - 如何找出字符串中以#开头的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65187892/

相关文章:

dart - 将 listView 传递到另一个屏幕

firebase - java.lang.IllegalArgumentException : Service not registered Flutter and Firebase Google SignIn 异常

python - 拆分每个第 N 个字符的字符串,并使用不同的分隔符将其连接回来

java - 将测试文件中的现有字符串与带有参数的新输入者对象进行比较时,始终返回 false

flutter :- Taking picture with camera

flutter - 如何在 flutter redux 中观察状态变化

angular - Dart Angular 形成原始/脏动态

flutter - 无法使用特定 block 的vs代码以 Dart (flutter)的方式折叠代码

c - 对字符串的子集使用 strcmp

sql - 如何从亚马逊 Redshift 中的字符串中删除非数字字符(句号 "."除外)