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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -