2017-01-18 1 views
3

ドキュメント(https://api.dartlang.org/stable/1.21.1/dart-core/RegExp-class.html)を読みましたが、探しているものが見つかりませんでした。私はそれを理解しなかったか、何かを見落とした。Googleダーツにはregex.exec()のようなものがありますか?

私はGoogleのダーツで、次を複製しようとしています:

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 
} 

私もjsfiddleを作成しました:https://jsfiddle.net/h3z88udz/

ダーツは、正規表現のexec(のようなものを持っていますか)?

答えて

4

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); 
    } 
} 

https://dartpad.dartlang.org/dd1c136fa49ada4f2ad4ffc0659aab51

+0

ありがとう!私はちょうど整数の両方を受け入れるグループ()とグループ()を含むメソッドのリストを見た。 – Asperger

関連する問題