暮色呼如
2021-04-29 14:20:25
我有帶有網(wǎng)址的字符串。因此,當(dāng)用戶鍵入它時,我必須在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貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個贊
您可以使用String#replace
method替換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貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超10個贊
這也可以工作,您可以使用join進(jìn)行字符串拆分
let str="Hello this my profilehttps://my_pforile and thishttps://my_profile2"
let newstring=str.split("profile").join("profile ");
console.log(newstring)
添加回答
舉報(bào)
0/150
提交
取消