【发布时间】:2017-11-05 19:59:28
【问题描述】:
我有一个遵循这个 url 模式的字符串
https://www.examples.org/activity-group/8712/activity/202803
// note : the end ending of the url can be different
https://www.examples.org/activity-group/8712/activity/202803?ref=bla
https://www.examples.org/activity-group/8712/activity/202803/something
我正在尝试编写一个匹配的正则表达式
https://www.examples.org/activity-group/{number}/activity/{number}*
其中 {number} 是长度为 1 到 10 的整数。
如何定义一个正则表达式来检查字符串模式并检查数字是否在字符串中的正确位置?
背景:在 Google 表单中,为了验证答案,我想强制人们以这种格式输入 url。因此使用了这个正则表达式。
对于不匹配该格式的 URL,正则表达式应返回 false。例如:https://www.notthesite.org/group/8712/activity/astring
我浏览了几个示例,但它们仅在字符串中存在数字时才匹配。
示例来源:
【问题讨论】:
-
展示你的最佳尝试。
-
抱歉,我不明白为什么
https://www\.examples\.org/activity-group/\d{1,10}/activity/\d{1,10}$没有帮助
标签: javascript regex google-forms