我在和弦打交道.该字符串通常包含以下内容:
"站点https://example.com包含您需要的所有信息."
到目前为止,我有这个正则表达式,它在https时拆分字符串?找到了
const rgx_link = /(?=https?:\/\/)/gi;
因此,在本例中,它会将字符串拆分为:
arr = ["The site ", "https://example.com contains all the information you need"];
我想修改正则表达式,这样如果在url之后发现一个空格,它也会拆分字符串.
所需结果如下所示:
arr = ["The site ", "https://example.com", " contains all the information you need"];
新的正则表达式"应该"看起来像这样的((?=https?:\/\/)(\s))
,但它不起作用.
任何帮助都将不胜感激.谢谢.
const text = "The site https://example.com contains all the information you need";
const rgx_link = /(?=https?:\/\/)/gi;
const result = text.split(rgx_link);
console.log(result)
编辑1:Wiktors的建议是正确的.我没有注意到正则表达式的前导部分被更改,所以它不起作用.
const text = "The site https://example.com contains all the information you need";
const rgx_link = /(https?:\/\/\S*)/gi;
const result = text.split(rgx_link);
console.log(result)