仅当 url 不以 http:// 开头时,正则表达式才用字符串替换部分 url
试图在堆栈溢出上找到答案,但我是一个十足的正则表达式菜鸟!
我所需要的(如果可能的话)就是在某些 HTML 中匹配 PDF URL,如果它不是以 http://
开头,则将 /content/
添加到开头,如果它确实以 http://
开头,则不执行任何操作。
Tried to find the answer on stackoverflow but I'm a complete RegEx noob!
All I need (if it's possible) is to match a PDF URL in some HTML and if it doesn't start with http://
add /content/
to the start, if it does start with http://
do nothing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你想要的正则表达式可能是
它说它必须以“http://add/content/”开头,然后可以有任何不是空白的东西,直到最后达到.pdf。
根据您使用的语言,您需要以不同的方式应用它。例如在 php 中它是
The regex you want is probably
Which says it must start with "http://add/content/" then can have anything which isn't a whitespace until it hits a .pdf at the end.
Depending on what language you use you will need to apply this differently. For example in php it would be
假设你想用 javascript 来做到这一点。
Assuming you want to do this with javascript.