簡體   English   中英

創建正則表達式以匹配特定 URI 模式時出錯

[英]Error with creating regex expression to match a specific URI pattern

開發者級別 -我最近開始了 web 開發。

問題 -
我一直在嘗試創建一個正則表達式來匹配代碼中的以下uri模式。

https://photos.google.com/share/`...`/photo/`...`?key=`...`

舉一個很好的例子 - ↓↓這個↓↓
https://photos.google.com/share/AF1QipPFB_fAYv9UKMfQJnS_AyinAMKN_NOfumadYm-N7WAdRhAjiKgfF03ejiHs2AumgQ/photo/AF1QipNDQb-ngSW1zIz4W338p225dMXVDDReKIAZULU?key=RmhDdS1FQnZEV0pid0o4dDlTX1MwWjdVZXhkOFZn

我一直在努力,但無法讓它發揮作用。 這是我的正則表達式 -
/\["(https:\/\/photos\.google\.com\/share\/[a-zA-Z0-9\-_]\*)"/g

基於項目 - NodeJS,表達

你可以使用它。

 function extract_url() { var content = "Content: https:google.com - https://photos.google.com/share/AF1QipPFB_fAYv9UKMfQJnS_AyinAMKN_NOfumadYm-N7WAdRhAjiKgfF03ejiHs2AumgQ/photo/AF1QipNDQb-ngSW1zIz4W338p225dMXVDDReKIAZULU?key=RmhDdS1FQnZEV0pid0o4dDlTX1MwWjdVZXhkOFZn https://photos.google.com/share/AF1QipPFB_fAYv9UKMfQJnS_AyinAMKN_NOfumadYm-N7WAdRhAjiKgfF03ejiHs2AumgQ/photo/AF1QipNDQb-ngSW1zIz4W338p225dMXVDDReKIAZULU?key=RmhDdS1FQnZEV0pid0o4dDlTX1MwWjdVZXhkOFZn"; var patt = /https:\/\/photos\.google\.com\/share\/[a-zA-Z0-9_-]+\/photo\/[a-zA-Z0-9_-]+\?key=[a-zA-Z0-9]+/; var result = content.match(patt); document.getElementById("urls").innerHTML = result; }
 <button onclick="extract_url()">Extract URL</button> <p id="urls"></p>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM