简体   繁体   English

使用正则表达式将所有URL中的空格替换为%20

[英]Replace spaces in all URLs with %20 using Regex

I have a large block of HTML that contains multiples URLs with spaces in them. 我有一大段HTML,其中包含多个URL,其中包含空格。 How do I used Regex to replace any space that occurs in a URL, with a '%20'. 如何使用Regex用'%20'替换URL中出现的任何空格。 The good thing is that all of the URLs end with '.pdf'. 好消息是所有URL均以“ .pdf”结尾。

Looking for something I could run in BBedit/Text Wrangler, or even PHP. 寻找可以在BBedit / Text Wrangler甚至PHP中运行的功能。

Example: http://www.site-name.com/dir/file name here.pdf 范例: http://www.site-name.com/dir/file name here.pdf : http://www.site-name.com/dir/file name here.pdf

Need to return: http://www.site-name.com/dir/file%20name%20here.pdf 需要返回: http://www.site-name.com/dir/file%20name%20here.pdf : http://www.site-name.com/dir/file%20name%20here.pdf

Instead of Regex you could use could use urlencode in PHP to achieve this which escapes the url for you. 您可以使用可以在PHP中使用urlencode代替Regex来实现此目的,从而为您避免使用url。 Similar to encodeURI in JavaScript. 类似于JavaScript中的encodeURI

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM