我有带有网址的字符串。因此,当用户键入它时,我必须在url前面添加空间。这是字符串:Hello this my profilehttps://my_pforile and thishttps://my_profile2我需要如下所示的字符串:Hello this my profile https://my_pforile and this https://my_profile2谁能帮我怎么做?
2 回答
幕布斯7119047
TA贡献1794条经验 获得超8个赞
您可以使用String#replacemethod替换https://为空白前缀。
let str = 'Hello this my profilehttps://my_pforile and thishttps://my_profile2';
console.log(
str.replace(/https:\/\//g, ' $&')
)
// or with positive look-ahead
console.log(
str.replace(/(?=https:\/\/)/g, ' ')
)
动漫人物
TA贡献1815条经验 获得超10个赞
这也可以工作,您可以使用join进行字符串拆分
let str="Hello this my profilehttps://my_pforile and thishttps://my_profile2"
let newstring=str.split("profile").join("profile ");
console.log(newstring)
添加回答
举报
0/150
提交
取消
