Google Dart是否有类似regex.exec()的东西?
我阅读了文档()但没有找到我要找的。要么我不明白,要么我忽略了什么 我试图在google dart中复制以下内容: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
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(),它们都接受整数。