我正在尝试创建一个正则表达式来检查用户发布的网址是否有效。
我创建了以下正则表达式:
/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”修饰符只是为了让您可以看到它在不同的字符串中测试它,但您可能不需要它。
关于javascript - 检查 Steam 配置文件 url 是否有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37016532/