If you move the line with the pattern here, I would do:
```java
  String javaVal = val
                   .replace("_","\\E.\\Q") 
                   .replace("*","\\E.*\\Q");
 Pattern pattern = Pattern.compile("\\Q" + javaVal + "\\E", Pattern.CASE_INSENSITIVE);
```
to avoid reassigning to the variable.