Java regex match not working -
i trying match string using java regex, match failing. may issue in code below?
string line = "copy of 001"; boolean b = pattern.matches("001", line); system.out.println("value : "+b); output value
value : false
matches match whole string. use matcher , find() method instead:
boolean b = pattern.compile("001").matcher(line).find(); or make pattern more flexible , allow have prefixing "001". example:
".*001" for simple, though, pattern overkill , simple indexof job more efficiently:
boolean b = line.indexof("001") > -1;
Comments
Post a Comment