[英]Regex to validate parameters in the URI
我正在尝试使用正则表达式验证系统的URI,以在REST API的URI中间标识参数,但是,在URI的末尾遇到参数验证问题,例如:
在数据库中,我获得了URI的规则: /uaa/api/users/*/city/*
用正则表达式替换“ *”,以便它接受/或/之后的任何字符: ^/uaa/api/users/+(.*)+/city/+(.*)$
我将带有正则表达式的URI与请求URI进行比较: /uaa/api/users/john.connor/city/12
但是,如果我删除URI末尾的值,而只保留/,则表示接受它需要我失败,因为/后面没有值,也就是说,使用^/uaa/api/users/+(.*)+/city/+(.*)$
带有/uaa/api/users/john.connor/city/
URI的正则表达式我需要它失败,因为/之后没有值。我该怎么做,所以他最终不接受毫无价值的酒吧吗?
我不知道这是否重要,但是我在Java中使用正则表达式!
它至少包含以下每个类别中的一个字符。
小写字符大写字符数字符号
(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*\W)
(?=.*[a-z]) // use positive look ahead to see if at least one lower case letter exists
(?=.*[A-Z]) // use positive look ahead to see if at least one upper case letter exists
(?=.*\d) // use positive look ahead to see if at least one digit exists
(?=.*\W]) // use positive look ahead to see if at least one non-word character exists
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.