Created
October 29, 2011 06:33
-
-
Save monsat/1324174 to your computer and use it in GitHub Desktop.
正規表現でgオプションをつけた場合の後方参照にはRegEx.exec()を利用する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var body = 'foo target1 target2 bar target3 hoge'; | |
var re = /¥s(target(¥d))¥s/g; | |
var results = []; | |
while (results = re.exec(body)) { | |
console.log(results); | |
// ['foo target1 target2 bar target3 hoge', 'target1', '1'] | |
// ['foo target1 target2 bar target3 hoge', 'target2', '2'] | |
// ['foo target1 target2 bar target3 hoge', 'target3', '3'] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment