JavaScript从字符串解析int

tuc*_*nak 1 javascript regex jquery

我有一个字符串:"你可以投票36次主题和84次评论".

我需要从字符串中获取数字84(数字可以不同).

我该怎么做?

qwe*_*ymk 8

试试这个:

/^You can vote \d\d times for topics and (\d\d) times for comments$/.exec(str);
Run Code Online (Sandbox Code Playgroud)

要么:

/^You can vote \d+ times for topics and (\d+) times for comments$/.exec(str);
Run Code Online (Sandbox Code Playgroud)