Home > Net >  How to convert string into list string on specific expression in Dart?
How to convert string into list string on specific expression in Dart?

Time:01-12

i have string who is

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

want to make list string who is taking who have {string} output :

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

its that possible in dart ?

i dont know what to use

CodePudding user response:

You can achieve this by using 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());

  •  Tags:  
  • dart
  • Related