【发布时间】:2015-10-30 18:37:08
【问题描述】:
我有这个 json 对象
arr[i].text
返回
check this http://www.newlook.com/shop/womens/dresses/navy-short-sleeve-check-tunic-dress-_320165649
我只想返回带有正则表达式的 URL,如下所示:
var urlreg = /(\bhttps?\:\/\/(www)?\.\w+\.\w+(\/[\w\d\-]+)*)/;
match = urlreg.exec(arr[i].text );
但是不起作用,它是一个对象而不是字符串吗?
【问题讨论】:
-
为我工作
'check this http://www.newlook.com/shop/womens/dresses/navy-short-sleeve-check-tunic-dress-_320165649'.match(/(\bhttps?\:\/\/(www)?\.\w+\.\w+(\/[\w\d\-]+)*)/)[1] -
你能给我们看看 JSON 字符串吗?
-
如果你像
match = urlreg.exec(""+arr[i].text);那样做呢?请参阅jsfiddle.net/zdyksaft,您的正则表达式正在使用简单的字符串输入。 -
也适合我。但是,这个正则表达式可以更普遍地用于域/子域匹配。检查我的答案。
标签: javascript regex