gpt4 book ai didi

javascript - 使用 JavaScript 正则表达式

转载 作者:行者123 更新时间:2023-11-28 12:39:12 25 4
gpt4 key购买 nike

我是 JavaScript 正则表达式新手..

这是我的问题:

http://example/uploads/files/full/images/image.png

我只想获取uploads/files/full/images/image.png

如何使用正则表达式来做到这一点?

帮助任何人..谢谢..

最佳答案

var someString = "http://example/uploads/files/full/images/image.png";
var path = someString.match(/https?:\/\/example\/(.+)$/)[1];

http://jsfiddle.net/Squeegy/QwHsC/

// matches http or https
https?

// matches :// since you have to escape slashes
:\/\/

// matches the domain name
example/

// captures the path all the way to the end of the string
(.+)$

关于javascript - 使用 JavaScript 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14017915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com