正则查询title为执金吾 区分大小写
正则查询title为wonder 不区分大小写
# 正则查找以执金吾开头的文章 区分大小写
article_list = Article.objects.filter(title__regex="^执金吾")
print(article_list.query)
# 不区分大小写
article_list2 = Article.objects.filter(title__iregex="^wonder")
print(article_list2.query)
输出如下
# 区分大小写
SELECT `article_article`.`id`, `article_article`.`title`, `article_article`.`label`, `article_article`.`content`, `article_article`.`article_type_id`, `article_article`.`author_id`, `article_article`.`read_count`, `article_article`.`like_count`, `article_article`.`create_time`, `article_article`.`update_time`, `article_article`.`show_info`, `article_article`.`cover_img`, `article_article`.`is_top`, `article_article`.`is_push_xiongzhang`, `article_article`.`md_text` FROM `article_article` WHERE `article_article`.`title` REGEXP BINARY ^执金吾 ORDER BY `article_article`.`is_top` DESC, `article_article`.`create_time` DESC
# 不区分大小写
SELECT `article_article`.`id`, `article_article`.`title`, `article_article`.`label`, `article_article`.`content`, `article_article`.`article_type_id`, `article_article`.`author_id`, `article_article`.`read_count`, `article_article`.`like_count`, `article_article`.`create_time`, `article_article`.`update_time`, `article_article`.`show_info`, `article_article`.`cover_img`, `article_article`.`is_top`, `article_article`.`is_push_xiongzhang`, `article_article`.`md_text` FROM `article_article` WHERE `article_article`.`title` REGEXP ^wonder ORDER BY `article_article`.`is_top` DESC, `article_article`.`create_time` DESC