Answer the question
In order to leave comments, you need to log in
How to convert a string with special characters (mask) into a pattern?
Hello.
I am writing a method to search for a file by name. To search for matches by substring, I solved the problem like this:
...
fileNameQuery = "asd";
...
if (file.getName().matches(".*" + asd + ".*"))
...
*sdf*.txt"
to a pattern" .*sdf.*\.txt
", *sdf?.txt"
to a pattern" .*sdf.+\.txt
", sd*.tx?"
to a pattern" sd.*\.tx?+
", etc. Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question