将正则表达式与Javascript一起使用

将正则表达式与Javascript一起使用,javascript,regex,ckeditor,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.m

我正试图在我的一个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);
  }
}
onOk:function(){
var sInsert=this.getValueOf('info','insertcode_area');
如果(正弦长度>0){

regex=new RegExp(“(?您正在使用“正向查找”
”(?以下是我最终如何做到的:

// 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), '');
不是正则表达式,但我们用现有的做我们能做的;)


无论如何,谢谢!

Yikes。我还以为几乎所有不支持基本高级RE的口味现在都早已过时了…@Tom:只要使用
/\?v=([-a-zA-Z0-9.-]+)/I
而不使用lookback断言即可。
// 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), '');