如何在Dart中将字符串转换为特定表达式上的列表字符串?



我有字符串谁是

String hello = "test test {Brian} have you {Adam} always and {Corner} always";

想让列表字符串谁是谁有{string}输出:

List<String> data = ["{Brian}","{Adam}","{Corner}"];

这在dart中是可能的吗?

我不知道该用什么

您可以通过使用RegExp(r"{[^{}]*}")

来实现这一点
String hello = "test test {Brian} have you {Adam} always and {Corner} always";
RegExp regExp = RegExp(r"{[^{}]*}");

print(regExp.allMatches(hello).map((e) => e[0]).toList());

最新更新