code: public static Pattern createRegexp(String likePattern)
     {
        // - escape all non alphabetic characters
        // - escape constructs like \<alphabetic char> into \\<alphabetic char>
        // - replace non escaped _ % into . and .*
        StringBuilder regexp = new StringBuilder();
        boolean escaped = false;
        for (int i = 0; i < likePattern.length(); i++)
        {
           if (likePattern.charAt(i) == '\\')
           {
              if (escaped)
              {
                 regexp.append("\\\\");
                 escaped = false;
              }
              else
              {
                 escaped = true;
              }
           }
           else
           {
              if (Character.isLetterOrDigit(likePattern.charAt(i)))
              {
                 if (escaped)
                 {
                    regexp.append("\\\\").append(likePattern.charAt(i));
                    escaped = false;
                 }
                 else
                 {
                    regexp.append(likePattern.charAt(i));
                 }
              }
              else
              {
                 if (escaped)
                 {
                    regexp.append('\\').append(likePattern.charAt(i));
                    escaped = false;
                 }
                 else
                 {
                    switch (likePattern.charAt(i))
                    {
                       case '_' :
                          regexp.append('.');
                          break;
                       case '%' :
                          regexp.append(".*");
                          break;
                       default :
                          regexp.append('\\').append(likePattern.charAt(i));
                    }
                 }
              }
           }
        }
        return Pattern.compile(regexp.toString(), Pattern.DOTALL);
     }
docs: Creates a regexp from <code>likePattern</code>.
  
  @param likePattern the pattern.
  @return the regular expression <code>Pattern</code>.