Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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正则表达式失败_Java_Regex_String_Matcher - Fatal编程技术网

JAVA正则表达式失败

JAVA正则表达式失败,java,regex,string,matcher,Java,Regex,String,Matcher,我有以下格式的字符串: ;1=2011-10-23T16:16:53+0530;2=2011-10-23T16:16:53+0530;3=2011-10-23T16:16:53+0530;4=2011-10-23T16:16:53+0530 Pattern pattern = Pattern.compile("(;1+)=(\\w+);"); String strFound= ""; Matcher matcher = pattern.matcher(strindData); while (m

我有以下格式的字符串:

;1=2011-10-23T16:16:53+0530;2=2011-10-23T16:16:53+0530;3=2011-10-23T16:16:53+0530;4=2011-10-23T16:16:53+0530

Pattern pattern = Pattern.compile("(;1+)=(\\w+);");

String strFound= "";
Matcher matcher = pattern.matcher(strindData);
while (matcher.find()) {
   strFound= matcher.group(2);
}
我编写了以下代码来查找
中的字符串
2011-10-23T16:16:53+0530
(;1=2011-10-23T16:16:53+0530;)

但它并没有像预期的那样发挥作用。你能给我一些提示吗

你能给我一些提示吗


对。
-
,或
,或
+
都不是
\w

的一部分,您必须使用正则表达式吗?为什么不调用
String.split()。然后再次调用它,用等号将这些块分开。此时,您将得到一个整数和字符串形式的日期。从那里你可以看到绳子


我对输入做了一些更改,但只是出于演示的原因

您可以尝试以下方法:

 String input = " ;1=2011-10-23T16:16:53+0530;   2=2011-10-23T16:17:53+0530;3=2011-10-23T16:18:53+0530;4=2011-10-23T16:19:53+0530;";

Pattern p = Pattern.compile("(;\\d+?)?=(.+?);");
Matcher m = p.matcher(input);

while(m.find()){
    System.out.println(m.group(2));
}
 String input = " ;1=2011-10-23T16:16:53+0530;   2=2011-10-23T16:17:53+0530;3=2011-10-23T16:18:53+0530;4=2011-10-23T16:19:53+0530;";

Pattern p = Pattern.compile("(;\\d+?)?=(.+?);");
Matcher m = p.matcher(input);

while(m.find()){
    System.out.println(m.group(2));
}