Java regex not matching, regex looks OK -
the following returns no matches:
string patternstr = "((19\\d{2}|20\\d{2})-([0-2]\\d{2}|3[0-5]\\d)-(([0-1]\\d|2[0-3])[0-5]\\d[0-5]\\d))"; string fullpath = afile.getabsolutepath(); // fullpath should expand this: "/home/user1/2013-023-135159_abcd_001/file.txt" pattern p = pattern.compile(patternstr); matcher m = p.matcher(fullpath); if (m.matches()) { system.out.println("matches found"); }
it should match date portion, 2013-023-135159. tested online , regex looks ok.
you need use:
m.find()
instead of:
m.matches()
as regex matching parts of input string not expected m.matches()
Comments
Post a Comment