简体   繁体   中英

issue with javascript function that implements regex

I am trying to get URL property of the row and it doesn't work, can you help me?I just want to grab the URL value after the pipe | and before ", Wheat Husk"

http://jsfiddle.net/6cJQZ/1

<z:row ows_Title='We are together!' ows_ImageSize='620' 
            ows_MetaInfo='16;#vti_parserversion:SR|14.0.0.6120&#13;&#10; 
            URL:SW|http://collaboration/sites/athapali/SliderImages/nature1.jpg, Wheat Husk&#13;&#10;               
            vti_lastheight:IW|250&#13;&#10;vti_lastwidth:IW|620&#13;&#10;
            vti_description:SW|Lorem ipsum dolor sit volutpat.' />

My Javascript returns null..

var myurl=getURL( $('[ows_MetaInfo]').attr("ows_MetaInfo"));
alert (myurl);

function getURL(str){
    str = str.replace(/(\r\n|\n|\r)/gm,"");
    str =   str.match(/URL:([^URL]*)/);
    str = parseInt(str[1].split('|')[1]);
    console.log(str);
    return str;
;}

Try this:

var myurl=getURL( $('[ows_MetaInfo]').attr("ows_MetaInfo"));

function getURL(str){
    str =   str.match(/URL:\w{2}\|(.+),/);
    alert(str[1]);   
    return str[1];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM