輸入字串的格式是 >>
[https://thisisurl.com] 這是名字
如何從中提取“https://thisisurl.com”和“This is url”屬性
其中 url 屬性在括號 [???] 中給出,其余文本是 name 屬性
我想要一個可以為我完成這項任務的功能
uj5u.com熱心網友回復:
您可以為此使用轉義字符\,如下所示:
const str = '[https://thisisurl.com] This is Name'
const regex = /\[(.*)\] (.*)/i
const matchResult = str.match(regex)
const url = matchResult[1]
const name = matchResult[2]
console.log(`url: "${url}" name: "${name}"`)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/453581.html
標籤:javascript 细绳 解析 文本提取
上一篇:如何將一個字串分成兩部分并將它們輸出為兩個不同的塊?
下一篇:將點陣列添加到多邊形
