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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -