[英]String length - incorrect result?
I can't understand what is wrong with the following code: 我不明白以下代码有什么问题:
System.out.println("TEST:"+"/index/index/(\\d+)/".length());
Output: TEST:19 . 输出:TEST:19。 But as I see there must be 20. Where is my mistake?
但是我认为必须有20个。我的错误在哪里?
In java, \\
is an escape character. 在Java中,
\\
是转义字符。
So: The \\\\
is actually a single \\
. 因此:
\\\\
实际上是单个\\
。
And therefore that part of the string reads like this: (\\d+)
, which as per regex definition means "1 or more digits" :) 因此,该字符串的部分内容如下:
(\\d+)
,根据正则表达式定义,其含义是“ 1个或多个数字” :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.