「トピックには 36 回、コメントには 84 回投票できます」という文字列があります。
文字列から番号 84 を取得する必要があります (番号は異なる場合があります)。
どうすればいいですか?
「トピックには 36 回、コメントには 84 回投票できます」という文字列があります。
文字列から番号 84 を取得する必要があります (番号は異なる場合があります)。
どうすればいいですか?
これを試して:
/^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);
または、これを少し違うものにしてみてください:デモ 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];