// pattern 20xx/xx/xx, e.g. 2012/2/22
String Regex_Date_1 = "20\\d\\d/\\d{1,2}/\\d{1,2}";
String cell = "from 2011/7/31 to 2011/8/15 15:10-17:40,18:30-21:00";
System.out.println(cell);
System.out.println("--- a ---");
System.out.println( cell.matches(Regex_Date_1) );
System.out.println("--- b ---");
Pattern p = Pattern.compile(Regex_Date_1);
Matcher m = p.matcher(cell);
while(m.find()){
System.out.println( m.group(0) );
}
結果:
from 2011/7/31 to 2011/8/15 15:10-17:40,18:30-21:00
--- a ---
false
--- b ---
2011/7/31
2011/8/15
string.matches が false を返すのはなぜですか? しかし、pattern.matches は一致を取得できますか?