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

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -