给定字符后如何选择子字符串 [英] How to choose a substring after given character

查看:46
本文介绍了给定字符后如何选择子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除非有其他/简便的方法,否则我想使用正则表达式将子字符串保存到javascript变量中.例如,我有这样的链接: http://www.youtube.com/watch?v=sEHN4t29oXY&feature=related

I would like to save a substring to a javascript variable using regex unless there is a different/easier way. For example i have a link like this: http://www.youtube.com/watch?v=sEHN4t29oXY&feature=related

我只想获取sEHN4t29oXY& feature = related,所以我想我必须检查第一个等号的出现,然后将其余的字符串保存到变量中..请帮助,谢谢

I want to only get sEHN4t29oXY&feature=related so i guess i would have to check for the first equal sign to appear and after that save the rest of that string into the variable.. please help, thanks

推荐答案

不带正则表达式,但也很简单,因为第一个url部分是静态的,长度为23个符号

not with regex, but simple too, because first url part is static and has 23 symbols length

'http://www.youtube.com/watch?v=sEHN4t29oXY&feature=related'.substr(23)

哦,我犯了一个错误,他想要另一个部分,因此实际代码如下:

Oh, I've made a mistake, he wants another part, so actual code will looks like:

'http://www.youtube.com/watch?v=sEHN4t29oXY&feature=related'.substr(31)

这篇关于给定字符后如何选择子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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