简体   繁体   English

Java正则表达式@path参数可选

[英]java regular expression @path param optional

i need help with a java regular expression, I need to accept HTTP request at these paths: 我需要Java正则表达式的帮助,我需要在以下路径接受HTTP请求:

categories
categories/533446dd2cdc5af82a027d9e,

533446dd2cdc5af82a027d9e stay for @Path param called "id";

I'm working on this regular expression: 我正在研究这个正则表达式:

categories(\/)?([a-z0-9]{0,25})?

but it's not working, can you help me? 但它不起作用,您能帮我吗? thanks guys :) 多谢你们 :)

Have a look at the following example : 看下面的例子:

String str1 = "categories/533446dd2cdc5af82a027d9e";
String str2 = "categories";
String pattern = "categories(/[a-z0-9]{0,24})?";
System.out.println(str1.matches(pattern));
System.out.println(str2.matches(pattern));

Output : 输出:

true
true

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

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