我有一個字串,其中包含陣列和括號,我想從中提取資料。
let vr = "- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API."
我如何動態識別此字串中是否存在陣列,例如 take ,[Next.js Documentation]因為它是一個陣列。請幫我解決這個問題
uj5u.com熱心網友回復:
您可以將正則運算式與 javascript 一起使用String.prototype.match()。
匹配括號括起來的任何內容的正則運算式模式是/\[(.*?)\]/gm. 你可以在這里查看。
祝你好運!
uj5u.com熱心網友回復:
let vr = "- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API."
const regex = /\[([^\]] )\]\(([^)] )\)/g;
let match;
let result = [];
while ((match = regex.exec(vr)) !== null) {
result.push(match[1]);
}
console.log(result);
uj5u.com熱心網友回復:
let vr = "- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API."
const re = /\[([^]*?)]/g;
let match = re.exec(vr);
if (match !== null) {
console.log(match[1]);
} else {
// not matched
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/433497.html
標籤:javascript 数组
上一篇:如何在Mongoose中使用findOne查找最新(相同)檔案
下一篇:vs代碼在引號中包含多行
