我有这个网址字符串
http://apistaging.yoolk.com/listings/F7B519E8-135C-43D0-A35F-764B582EDC48?domain_name=cambodiastaging.yoolk.com&display=basic
我想通过在Javascript中使用正则表达式从此网址获取uuid F7B519E8-135C-43D0-A35F-764B582EDC48
。我怎么能这样做?请给我一些建议。
谢谢大家。
答案 0 :(得分:9)
/((\w{4,12}-?)){5}/.exec(URL)[0]
答案 1 :(得分:1)
var url = 'http://apistaging.yoolk.com/listings/F7B519E8-135C-43D0-A35F-764B582EDC48?domain_name=cambodiastaging.yoolk.com&display=basi',
matches = url.match(/listings\/([A-F\d-]+)\?/),
UUID = matches[1];
console.log(UUID); // F7B519E8-135C-43D0-A35F-764B582EDC48
答案 2 :(得分:0)
我会用分裂来做。
var uri = 'http://apistaging.yoolk.com/listings/F7B519E8-135C-43D0-A35F-764B582EDC48?domain_name=cambodiastaging.yoolk.com&display=basic'
uri.split('?')[0].split('/')[4]