我有一个正则表达式,它替换了从http到[]
中出现某些字符的链接,我想在这些字符中添加
个字符,也就是用出现的某些字符或硬空格替换字符串:
"https://test.pl'".replace(/https?:\/\/[^ "'><]+/g," ")
适用于[]
中提到的角色,我不知道如何在这里添加 
;
我有一个正则表达式,它替换了从http到[]
中出现某些字符的链接,我想在这些字符中添加
个字符,也就是用出现的某些字符或硬空格替换字符串:
"https://test.pl'".replace(/https?:\/\/[^ "'><]+/g," ")
适用于[]
中提到的角色,我不知道如何在这里添加 
;
你可以用
.replace(/https?:\/\/.*?(?: |[ '"><]|$)/g," ")
Details:
https?:\/\/
-http://
或https://
.*?
-除换行符以外的任何零个或多个字符尽可能少(?: |[ '"><]|$)
- one of the following:
-
字符序列|
-或[ "'><]
-一个空格,"
、'
、>
或<
个字符|
-或$
-绳子的末端.JavaScript演示:
const texts = ["https://test.pl test","https://test.pl'test"];
const re = /https?:\/\/.*?(?: |[ '"><]|$)/g;
for (const s of texts) {
console.log(s, '=>', s.replace(re, " "));
}