使用正则表达式与Javascript

Tom*_* B. 0 javascript regex ckeditor

我正试图在我的一个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);
  }
}
Run Code Online (Sandbox Code Playgroud)

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

但我目前收到此错误:

invalid quantifier ?<=?v=)([-a-zA-Z0-9_-]+)
Run Code Online (Sandbox Code Playgroud)

所以我认为这是一个正常的错误,因为我不经常使用正则表达式,也许我从未见过这一个:)所以,如果有人能帮助我,那将是伟大的:)

谢谢!

Dia*_*tis 7

您正在使用(?<=)javascript不支持的"正面lookbehind"