Home > Software design >  Regex to find all Strings enclosed between two Strings in Dart
Regex to find all Strings enclosed between two Strings in Dart

Time:09-01

I'd like to find all occurrences of strings in a long string which are placed between a set of two specific strings.

For eg.

String s = "abcdText('hello')abcd efghText('world')";

The regex pattern of strings would be Text(' and next ' and the results should be the List of strings enclosed between the pattern. Hence the expected output should be:

[hello, world]

After some searches, I found enter image description here

EDIT

  String myString = "abcdText('hello')abcd efghText('world')";
  RegExp exp = RegExp(r"Text\('(.*?)'\)");
  List<String> _list =[];
  for (var m in exp.allMatches(myString)) {
    _list.add(m[1].toString());
   
  }
  
  print(_list);
  • Related