Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java正则表达式:(\\d{1,2})\\/(\\d{1,2})\\/(\\d{1,4})_Java_Regex - Fatal编程技术网

java正则表达式:(\\d{1,2})\\/(\\d{1,2})\\/(\\d{1,4})

java正则表达式:(\\d{1,2})\\/(\\d{1,2})\\/(\\d{1,4}),java,regex,Java,Regex,我想知道:(\\d{1,2})\\/(\\d{1,2})\\/(\\d{1,4})的意思 我知道“\d{1,2}”表示“1到2个数字”,“\/”表示“/” 但我不知道其余的事情是什么意思。为什么有这么多“\”!对我来说,这很重要 应该是“\/”而不是“\\/”,并且“\d”而不是“\\d” 我已经运行了这个程序。它工作得非常好。以下是节目的一部分 /** Constructs a Date object corresponding to the given string. * @para

我想知道:(\\d{1,2})\\/(\\d{1,2})\\/(\\d{1,4})的意思

我知道“\d{1,2}”表示“1到2个数字”,“\/”表示“/”

但我不知道其余的事情是什么意思。为什么有这么多“\”!对我来说,这很重要

应该是“\/”而不是“\\/”,并且“\d”而不是“\\d”

我已经运行了这个程序。它工作得非常好。以下是节目的一部分

/** Constructs a Date object corresponding to the given string.
   *  @param s should be a string of the form "month/day/year" where month must
   *  be one or two digits, day must be one or two digits, and year must be
   *  between 1 and 4 digits.  If s does not match these requirements or is not
   *  a valid date, the program halts with an error message.
   */
  public Date(String s) {if (s.matches("(\\\d{1,2})\\\\/(\\\d{1,2})\\\\/(\\\d{1,4}) "))      //this is the first line of the 

object.

  }

您可能正在用一种语言(如JavaScript)构建正则表达式,在这种语言中,反斜杠需要先转义,然后才能解释为正则表达式的一部分

在这种情况下,
\\d
将减少为一个文字反斜杠,后跟d(
\d
),这将作为查找数字的术语进行计算

如果不清楚,此问题及其答案可能会加深您的理解:

在Java字符串文字中,
\
字符是转义字符,例如,由于Java字符串以
开头和结尾,字符串中的任何
字符都必须转义为
\“
。这也适用于字符串中的任何
\
字符,必须以
\
的形式给出。这就是为什么每个
\
都加倍了。非常感谢。我得到了它!O(∩_∩)可能相关-