Hello this my profilehttps://my_pforile and thishttps://my_profile2
我需要如下所示的字符串:
Hello this my profile https://my_pforile and this https://my_profile2
谁能帮我怎么做?
暮色呼如
浏览 240回答 2
2回答
幕布斯7119047
您可以使用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-aheadconsole.log( str.replace(/(?=https:\/\/)/g, ' '))
这也可以工作,您可以使用join进行字符串拆分let str="Hello this my profilehttps://my_pforile and thishttps://my_profile2"let newstring=str.split("profile").join("profile ");console.log(newstring)