我有一個這樣的字串:This is a string [img https://url.com/img.jpg]
我想通過搜索“[img]”模式并獲取其中的文本(即在上面,只是https://url.com/img.jpg)來獲取字串并僅分離出 URL
有沒有辦法用正則運算式做到這一點?“[]”讓我不知道如何寫出一個。
uj5u.com熱心網友回復:
您需要做的就是用\
. 像這樣:
const str = "This is a string [img https://url.com/img.jpg]"
const url = str.match(/\[img ([^\]] )\]/)[1];
console.log(url); // => https://url.com/img.jpg
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/529951.html