Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google Dart是否有类似regex.exec()的东西?_Dart - Fatal编程技术网

Google Dart是否有类似regex.exec()的东西?

Google Dart是否有类似regex.exec()的东西?,dart,Dart,我阅读了文档()但没有找到我要找的。要么我不明白,要么我忽略了什么 我试图在google dart中复制以下内容: var regex = /foo_(\d+)/g, str = "text foo_123 more text foo_456 foo_789 end text", match = null; while (match = regex.exec(str)) { console.log(match); // matched capture groups

我阅读了文档()但没有找到我要找的。要么我不明白,要么我忽略了什么

我试图在google dart中复制以下内容:

var regex = /foo_(\d+)/g,
    str = "text foo_123 more text foo_456 foo_789 end text",
    match = null;

while (match = regex.exec(str)) {
    console.log(match); // matched capture groups
    console.log(match.index); // index of where match starts in string
    console.log(regex.lastIndex); // index of where match ends in string
}
我还创建了一个JSFIDLE:


dart是否具有类似regex exec()的功能?

RegExp.allMatches
看起来它可以满足您的需要

var regex = new RegExp(r"foo_(\d+)");
var str = "text foo_123 more text foo_456 foo_789 end text";

void main() {
  for (var match in regex.allMatches(str)) {
    print(match);
    print(match.start);
    print(match.end);
  }
}

谢谢,它很管用!我刚才看到的方法列表包括Group()和Groups(),它们都接受整数。