Reputation: 524
I have string having urls. So when the user type it i have to add space in front of the url.
This is the string:
Hello this my profilehttps://my_pforile and thishttps://my_profile2
I need the string like below:
Hello this my profile https://my_pforile and this https://my_profile2
Can anyone help me how to do this?
Upvotes: 2
Views: 177
Reputation: 1
This can work also,You can string split with join
let str="Hello this my profilehttps://my_pforile and thishttps://my_profile2"
let newstring=str.split("profile").join("profile ");
console.log(newstring)
Upvotes: 1
Reputation: 115222
You can use String#replace
method to replace https://
with a white-space prefix.
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, ' ')
)
Upvotes: 2