正则表达式查找两个字符串之间的字符串

时间:2020-03-06 18:42:45

标签: javascript

例如,我如何在字符串server: rootPath: /api bootstrap.addBundle(new AssetsBundle("/build", "/", "index.html")); bootstrap.addBundle(new AssetsBundle("/build", "/login", "index.html")); bootstrap.addBundle(new AssetsBundle("/build", "/dashboard", "index.html")); 中找到example.com,例如如何用正则表达式找到一个字符串

https://example.com/path

2 个答案:

答案 0 :(得分:2)

为什么不使用URL

const url = new URL("https://example.com/path");
console.log(url.hostname)

答案 1 :(得分:0)

您想知道字符串是否包含吗?

console.log(!!('https://example.com/path'.match(/example\.com/)))

此外,请检查以下内容: https://www.w3schools.com/jsref/jsref_includes.asp

可能对您有用

相关问题