【发布时间】:2021-04-12 20:01:20
【问题描述】:
我正在尝试从“推文”中的字符串中提取域名,如何避免从字符串中提取双反斜杠? 我在 let url 中定义的正则表达式
let tweets = [
"Thank you to the Academy and the incredible cast & crew of #TheRevenant. #Oscars",
"@HardingCompSci department needs student volunteers for #HourOfCode https://hourofcode.com/us",
"Checkout the most comfortable earbud on #Kickstarter and boost your #productivity https://www.kickstarter.com/",
"Curious to see how #StephenCurry handles injury. http://mashable.com/2016/04/25/steph-curry-knee-injury-cries-cried/"
];
let url = /\/\/.+?\.com?/;
tweets.forEach(function(tweet) {
console.log(url.exec(tweet));
});
【问题讨论】:
标签: javascript