title: Using MySQL REGEXP to filter string with Django ORM
body: <p>I have a model which have <code>FileField</code> field and in this model we have millions of records.</p>
  <pre><code>class MyModel(models.Model):
      media = models.FileField(upload_to=my_function, db_index=True)
      ...
  </code></pre>
  <p>These media records are stored in database like;</p>
  <ul>
  <li>media/some/folder/filename.jpg</li>
  <li>media/filename.jpg</li>
  <li>media/2021091240-10328.JPG</li>
  <li>media/aXay-123.jpeg</li>
  <li>media/some/another/folder/202110-12-12.jpeg</li>
  </ul>
  <p>etc. and I need to find records which are not have nested path like <code>/some/folder/</code> or <code>/some/another/folder/</code> with django orm <code>__iregex</code> lookup.</p>
  <p>So, I tried something like;</p>
  <pre><code>MyModel.objects.filter(media__iregex=r&quot;^media/[0-9a-zA-Z\-][.][a-zA-Z]&quot;)
  </code></pre>
  <p>but it does not match and I do not understand to write proper regex <a href="https://dev.mysql.com/doc/refman/8.0/en/regexp.html#operator_regexp" rel="nofollow noreferrer">[mysql regexp]</a>.</p>
  <p>How can I do filter with mysql regexp with using Django orm to get records with only have pattern like; <code>media/filename.extension</code>?</p>