简体   繁体   中英

Regex to find all Strings enclosed between two Strings in Dart

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 ' 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 this . This explains my use case but it is in PHP and only meant to find digits.

You can try this way:

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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM