code: @SuppressWarnings("unchecked")
      public static Expression<String> regexToLike(Expression<String> expr) {
          if (expr instanceof Constant<?>) {
              final String str = expr.toString();
              final StringBuilder rv = new StringBuilder(str.length() + 2);
              boolean escape = false;
              for (int i = 0; i < str.length(); i++) {
                  final char ch = str.charAt(i);
                  if (!escape && ch == '.') {
                      if (i < str.length() - 1 && str.charAt(i + 1) == '*') {
                          rv.append('%');
                          i++;
                      } else {
                          rv.append('_');
                      }
                      continue;
                  } else if (!escape && ch == '\\') {
                      escape = true;
                      continue;
                  } else if (!escape && (ch == '[' || ch == ']' || ch == '^' || ch == '.' || ch == '*')) {
                      throw new QueryException("'" + str + "' can't be converted to like form");
                  } else if (escape && (ch == 'd' || ch == 'D' || ch == 's' || ch == 'S' || ch == 'w' || ch == 'W')) {
                      throw new QueryException("'" + str + "' can't be converted to like form");
                  }
                  rv.append(ch);
                  escape = false;
              }
              if (!rv.toString().equals(str)) {
                  return ConstantImpl.create(rv.toString());
              }
          } else if (expr instanceof Operation<?>) {
              Operation<?> o = (Operation<?>) expr;
              if (o.getOperator() == Ops.CONCAT) {
                  Expression<String> lhs = regexToLike((Expression<String>) o.getArg(0));
                  Expression<String> rhs = regexToLike((Expression<String>) o.getArg(1));
                  if (lhs != o.getArg(0) || rhs != o.getArg(1)) {
                      return operation(String.class, Ops.CONCAT, lhs, rhs);
                  }
              }
          }
          return expr;
      }
docs: Convert the given expression from regex form to like
  
  @param expr expression to convert
  @return converted expression