我有以下 reg ex 并且我是新手:
https:\/\/www.google-analytics.com\/.*
我用來測驗的字串是:
https://www.google-analytics.com/collect?v=1&ec=click&ea=test
https://www.google-analytics.com/collect?v=1&ea=tes
目前,兩個字串都將通過這個檢查,就像我/.*在正則運算式結束時所做的那樣,但我想要的是這應該只檢查ec=click引數并且只有第一個測驗字串應該通過(https://www.google-analytics.com/collect?v=1&ec=click&ea=test)......有誰知道我怎么能做這個?
游樂場鏈接:https ://regex101.com/r/mIjGjD/1
先感謝您
uj5u.com熱心網友回復:
https:\/\/www.google-analytics.com\/(.*)&ec=click(.*)
我想這就是你想要的
uj5u.com熱心網友回復:
這個正則運算式應該可以作業。請注意,我添加了一個 map 函式,以便在 url 陣列中獲取所有可能的匹配項
const urls = [
"https://www.google-analytics.com/collect?v=1&ec=click&ea=test",
"https://www.google-analytics.com/collect?v=1&ea=test"
];
const reg = /https:\/\/www\.google-analytics\.com\/.*&ec=click.*/;
const matches = urls.map(url => url.match(reg) || []).flat();
console.log(matches)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/418810.html
標籤:
上一篇:ImportError:無法從'django.conf.urls'django-rest-auth匯入名稱'url'
