我的 java 正则表达式有问题。我有类似的东西
com/products/id/response.html
我想要 id 为 Aa-Zz 0-9 中的任何内容,我已经尝试过了:
com/products/A-Za-z0-9]+/response.html
但是没有成功,但在这种情况下
com/products/A-Za-z0-9]+.html
效果很好... 知道我在哪里犯错了吗?
最佳答案
- 字符类别为
[...]
并且您缺少[
- 您需要转义点
- Jave 需要
\\
进行转义
您可以使用此正则表达式:
com/products/[A-Za-z0-9]+/response\\.html
- 您可能还需要使用 anchor
^
和$
。
关于Java正则表达式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21887690/