gpt4 book ai didi

javascript - 在字符串中的 url 前面插入空格

转载 作者:行者123 更新时间:2023-11-29 18:42:30 26 4
gpt4 key购买 nike

我有带有 url 的字符串。因此,当用户键入它时,我必须在 url 前面添加空格。

这是字符串:

你好,这是我的个人资料 https://my_pforile 和 thishttps://my_profile2

我需要如下字符串:

你好,这是我的个人资料 https://my_pforile 和这个 https://my_profile2

谁能帮我解决这个问题?

最佳答案

您可以使用 String#replace用空格前缀替换 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, ' ')
)

关于javascript - 在字符串中的 url 前面插入空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55963563/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com