[英]How to resolve a steam custom vanity profile URL to steamID64
[英]Check if valid steam profile url
我正在嘗試制作一個正則表達式來檢查用戶發布的 url 是否有效。
我創建了以下正則表達式:
/https?\\:\\/steamcommunity\\/.com\\/profiles|id\\/[a-zA-Z0-9]/
但這不起作用。 是否有正則表達式大師,可以告訴我我做錯了什么?
我試圖驗證的鏈接看起來像:
https://steamcommunity.com/profiles/76561198009610232/ https://steamcommunity.com/id/rasmusvejby/
回答
/(?:https?:\/\/)?steamcommunity\.com\/(?:profiles|id)\/[a-zA-Z0-9]+/
試試這個正則表達式:
(?:https?:\/\/)?steamcommunity\.com\/(?:profiles|id)\/[a-zA-Z0-9]+
看這個演示:
“g”修飾符只是為了讓您可以看到它在不同的字符串中測試它,但您可能不需要它。
此問題的已接受答案也將匹配此 url,例如:
https://steamcommunity.com/profile/thisisimpossible
當 id 由 profile/ 而不是 id/ 前綴時,我使用以下正則表達式來防止非數字字符。 不一定更漂亮,但它可以完成工作。
^(?:https?:\/\/)?steamcommunity\.com\/(?:profiles\/[0-9]{17}|id\/[a-zA-Z0-9].*)$
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.