提取斜线之间的数字 [英] Extract number between slashes

查看:67
本文介绍了提取斜线之间的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的设置:

var test = 
"http://tv.website.com/video/8086844/randomstring/".match(/^.+tv.website.com\/video\/(.*\d)/);

我想提取视频id(8086844),并且正则表达式可以正常工作,但是在随机字符串"之后添加另一个数字时,它也匹配8086844 +随机字符串+其他数字.

I want to extract the video id(8086844) and the regex does work, however when another digit is added after the "randomstring", it also matches the 8086844 + randomstring + other number.

要始终获得视频ID,我必须更改什么.

What do I have to change in order to always get just the video id.

推荐答案

尝试此正则表达式

/^.+tv.website.com\/video\/([\d]+)/

它将搜索...video\词后的每个数字字符,然后给出所有一致的数字,直到出现任何非数字字符为止

It will search every digit character after ...video\ word and then give all the concordant digits thereafter till any non-digit character comes

这篇关于提取斜线之间的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆