0

我正在尝试在我的一个 CKEditor 插件中做一些小事情:

onOk:function(){
    var sInsert=this.getValueOf('info','insertcode_area');
    if ( sInsert.length > 0 ) {
    regex = new RegExp('(?<=\?v=)([-a-zA-Z0-9_-]+)', 'gi');

    url = 'http://www.youtube.com/v/'+sInsert.match(regex);
        sInsert = '<object type="application/x-shockwave-flash" data="'+url+'" width="425" height="350"><param name="movie" value="'+url+'" /><a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&#038;promoid=BIOW" target="blank"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get flash player to play to this file" width="88" height="31" /></a><br /></object>';

        e.insertHtml(sInsert);
  }
}

它应该做什么:将 YouTube 的视频代码与输入的 URL 匹配,并将其连接到我的 url 字符串,这样 URL 是有效且可嵌入的。

但我目前收到此错误:

invalid quantifier ?<=?v=)([-a-zA-Z0-9_-]+)

所以我认为这是一个正常的错误,因为我不经常使用正则表达式,也许我从来没有见过这个:) 所以如果有人可以帮助我,那就太好了:)

谢谢!

4

2 回答 2

7

(?<=)您正在使用javascript 不支持的“正向后视”

于 2010-01-18T14:20:33.137 回答
0

这是我最终做到的方式:

// First I replace those, so it'll become a valid YouTube embeddable URL.    
url = sInsert.replace('watch?v=', 'v/');
// Then I remove all the crap after the URL.
url = url.replace(url.substr(url.indexOf('&', 0), url.length), '');

不是正则表达式,但是我们用我们拥有的东西做我们可以做的事情;)

不管怎么说,多谢拉!

于 2010-01-18T14:39:22.800 回答