Search code examples
javacase-insensitivematcher

Don't know what pattern and matcher does


Hi this is part of an example question..I would like to know what exactly this code does.

 if (Pattern.compile(".*" + search + ".*", Pattern.CASE_INSENSITIVE).matcher(one).matches());

Solution

  • This is a Regular expression. Basically, the code is the check that content of a search variable is contained in the text of one variable.

    .* means 'any character' (.) 'zero or more times' (*), So the pattern is search surrounded by any number of any characters.