title: Hibernate Regex
body: <p>I am trying to build an API which can search by HQL regex keywords,</p>
  
  <p>EDITED:
  The best way to perform regex search in HQL is to use criteria, Restrictions.like() or Restrictions.ilike().</p>
  
  <pre><code>public static List&lt;Object&gt; createQueryAnd(Criteria cri,
          ArrayList&lt;Parameters&gt; list) {
  
      for (Parameters p : list) {
          String value = (String) p.value;
          if (value.contains("*")) {
              value = value.replace("*", "%");
          } else {
              value += "%";
          }
          Criterion c1 = Restrictions.ilike(p.property, value);
          cri.add(c1);
  
      }
  
      return cri.list();
  }
  </code></pre>
  
  <p>Hope this helps someone</p>