为了账号安全,请及时绑定邮箱和手机立即绑定

在字符串中的网址前面插入空格

在字符串中的网址前面插入空格

暮色呼如 2021-04-29 14:20:25
我有带有网址的字符串。因此,当用户键入它时,我必须在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, ' ')

)


查看完整回答
反对 回复 2021-05-20
?
动漫人物

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)


查看完整回答
反对 回复 2021-05-20
  • 2 回答
  • 0 关注
  • 239 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信