我需要编写一个函数(Javascript),该函数接受'/';但是在';之前停止';

我需要编写一个函数(Javascript),该函数接受'/';但是在';之前停止';,javascript,Javascript,我在Dell Boomi中运行工作流,API只返回顶级字符串中的帐户ID,如下所示- api.tempo.io/core/3/user-schedule/5e5316c73011ed0c8f8b722e?from=2021-01-01&to=2021-01-31 我需要存储-5e5316c73011ed0c8f8b722e 有没有一种方法可以使用JavaScript从中提取我想要的字符串? s=“api.tempo.io/core/3/user schedule/5e5316c7301

我在Dell Boomi中运行工作流,API只返回顶级字符串中的帐户ID,如下所示-

api.tempo.io/core/3/user-schedule/5e5316c73011ed0c8f8b722e?from=2021-01-01&to=2021-01-31
我需要存储-
5e5316c73011ed0c8f8b722e

有没有一种方法可以使用JavaScript从中提取我想要的字符串?

s=“api.tempo.io/core/3/user schedule/5e5316c73011ed0c8f8b722e?from=2021-01-01&to=2021-01-31”
搜索“=”时间表“;
start=s.indexOf(search)+search.length+1;
end=s.indexOf(“?”);
结果=s.子串(开始、结束);

控制台日志(结果)您可以这样做:

consturl='1〕https://api.tempo.io/core/3/user-schedule/5e5316c73011ed0c8f8b722e?from=2021-01-01&to=2021-01-31';

const res=new URL(URL).pathname.match(/(?这里是另一种创建可能可重用的清晰函数名的方法:

const getPathname=(url)=>{
返回新URL(URL).pathname
}
常量getLastPath=(路径名)=>{
const path=pathname.split(“/”)
常量[结果]=路径.切片(-1)
返回结果
}
常量h='http://'
常数s='api.tempo.io/core/3/user schedule/5e5316c73011ed0c8f8b722e?from=2021-01-01&to=2021-01-31'
常量结果=getLastPath(getPathname(h+s))
console.log(结果)