需要有关 JAX-RS 路径模板正则表达式的帮助
我有一个 JAX-RS 服务,它可以与以下路径模板配合得很好:
@Path("/country/{countryIso:\\w{2}}")
来扩展它
@Path("/country/{countryIso:.+}")
但现在我想通过将其更改为Which will match any strings after "/country/
" 。但我不知道如何将这些字符限制为我之前的正则表达式。我想强制为每个国家/地区 ISO 代码仅提供 2 个字符。
示例: http://localhost/myService/country/BR/MX - 应该有效
http://localhost/myService/country/BR/fred - 应该无效且不允许。
非常感谢任何帮助。 提前致谢。
I have a JAX-RS service that works very well with the following path template:
@Path("/country/{countryIso:\\w{2}}")
But now I want to expand on that by changing it to
@Path("/country/{countryIso:.+}")
Which will will match any stream of characters after "/country/
". But I can't figure out how to restrict those characters to the regex that I had previously. I want to enforce that only 2 characters are provided for each country ISO code.
Examples:
http://localhost/myService/country/BR/MX - should be valid
http://localhost/myService/country/BR/fred - should be invalid and not allowed.
Any help is greatly appreciated.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否可以使用:
这将匹配 BR、BR/MX、BR/MX/ad,但不匹配 BR/fred。
Could you perhaps use:
That would match BR, BR/MX, BR/MX/ad but not BR/fred.