简体   繁体   English

正则表达式以验证最后一位数字

[英]Regular expression to validate last digits

How can I validate the last digits of URL /?d=123 如何验证URL的最后一位数字/?d=123

the URL will always ends with /?d=(no more than 4 numbers) ex.12345 will never appear 该网址将始终以/?d =(不超过4个数字)结尾,例如12345将永远不会出现

http://www.test.com/?d=123

This is what i have, but I don't know how to match just the ones that end with 123 and 4321 这就是我所拥有的,但我不知道该如何匹配仅以1234321结尾的那些

(http(s)?://)([\w-]+\.)+[\w-]+(/[\w- ;,./?%&=]*)?

Regex to validate a URL for which the query parameter contains only digits (1 to 4 like OP suggested): 使用正则表达式验证查询参数仅包含数字的URL(建议使用OP,建议使用1到4):

^(http(s)?://)([\w-]+.)+[\w-]+([\w- ;,./%&=]*)\?((\w)+=(\d){1,4})$

Regex to validate a URL for which query parameters are either 123 or 4321: 使用正则表达式验证查询参数为123或4321的URL:

^(http(s)?://)([\w-]+.)+[\w-]+([\w- ;,./%&=]*)\?((\w)+=(123|4321))$

Refiddle Demo Refiddle演示

Regexstorm Demo Regexstorm演示

EDIT: Minor modifications as per OP's requirements and @Stephen P's suggestions 编辑:根据OP的要求和@Stephen P的建议进行的细微修改

这仅用于最后匹配这些值:

/(123|4321)$/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM