regular expression for link

前端 未结 2 763
攒了一身酷
攒了一身酷 2021-01-28 00:13

i need to trim this string -> http://hokuspokus/ixdebude/ix and i exactly Need this part of the string /ixdebude/ix

I have 2 expressions to solve my P

2条回答
  •  花落未央
    2021-01-28 00:55

    You could use a regex like this:

    //.*?(/.*)
    

    Working demo

    For javascript, you could use:

    var re = /\/\/.*?(\/.*)/; 
    var str = 'http://hokuspokus/ixdebude/ix';
    var m;
    
    if ((m = re.exec(str)) !== null) {
        if (m.index === re.lastIndex) {
            re.lastIndex++;
        }
        // View your result using the m-variable.
        // eg m[0] etc.
    }
    

提交回复
热议问题