search

Home  >  Q&A  >  body text

javascript - regular matching characters

url = ‘http://1dwen.cn/index.php/joi...’
How to use regular expression to match the value 22 after uid? Can any expert help me?

某草草某草草2808 days ago801

reply all(5)I'll reply

  • 代言

    代言2017-06-12 09:32:09

    'http://1dwen.cn/index.php/uid/22/join/team_list?share_text=3&share_pic=12'.match(/http:\/\/1dwen\.cn\/index\.php\/uid\/(\d+)/)[1]

    reply
    0
  • 扔个三星炸死你

    扔个三星炸死你2017-06-12 09:32:09

    Can I understand that you only need to match the last number

    \d+(?=[^\d]*$)

    reply
    0
  • PHP中文网

    PHP中文网2017-06-12 09:32:09

    /https?:\/\/(?:[^\/]+\/)+(\d+)/

    reply
    0
  • 大家讲道理

    大家讲道理2017-06-12 09:32:09

    var url = new URL("http://1dwen.cn/index.php/join/team_list/uid/22?share_text=3&share_pic=12");
    var pathname = url.pathname;
    var reg = /\d+$/gi;
    var result = pathname.match(reg);
    
    

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-06-12 09:32:09

    For js or java, you can use methods such as indexOf and subString

     var index = 'asdf'.indexOf('s') ;//  ---> 1
     'asdf'.substring(index); //....

    If you are using regular expressions (js version), you can use regular expression grouping:

    t = /uid\/(.*)\?/.exec('http://1dwen.cn/index.php/join/team_list/uid/22?share_text=3&share_pic=12');
    console.log(t[1]);

    reply
    0
  • Cancelreply