1

「トピックには 36 回、コメントには 84 回投票できます」という文字列があります。

文字列から番号 84 を取得する必要があります (番号は異なる場合があります)。

どうすればいいですか?

4

2 に答える 2

8

これを試して:

/^You can vote \d\d times for topics and (\d\d) times for comments$/.exec(str);

または:

/^You can vote \d+ times for topics and (\d+) times for comments$/.exec(str);
于 2012-06-26T12:18:20.487 に答える
2

または、これを少し違うものにしてみてください:デモ http://jsfiddle.net/GyK7J/

コード

var s = "You can vote 36 times for topics and 84 times for comments".;
var firstnumber = parseInt(/vote\s(\d+)/.exec(s)[1], 10);
var second = /and\s([\d+]+)/.exec(s)[1];
于 2012-06-26T12:24:03.447 に答える