正则表达式匹配Javascript数字

Bre*_*ent 4 javascript regex jquery

我尝试了一些不同的技术来匹配我的DIV中的数字但仍然失败.

目前我的示例html如下所示.

<div data-video="22" class="stars starrr"></div>
<div data-video="/test/22" class="stars starrr"></div>
<div data-video="/someother/test/22" class="stars starrr"></div>
Run Code Online (Sandbox Code Playgroud)

我只需要匹配视频中的数字,但我会继续让它与某些人合作并与其他人失败.

我目前的代码

$(this).data("video").match(/([\d]+)/);
Run Code Online (Sandbox Code Playgroud)

第一场比赛的当前错误其他人工作

未捕获的TypeError:undefined不是函数

Ale*_* K. 5

你需要在第一种情况下强制转换为字符串;

var f = $(this).data("video").toString().match(/([\d]+)/);
Run Code Online (Sandbox Code Playgroud)

因为typeof $(this).data("video")number这样不.match