我是靠谱客的博主 舒适路灯,最近开发中收集的这篇文章主要介绍java sql like,如何在java中实现类似'LIKE'运算符的SQL?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

I need a comparator in java which has the same semantics as the sql 'like' operator.

For example:

myComparator.like("digital","%ital%");

myComparator.like("digital","%gi?a%");

myComparator.like("digital","digi%");

should evaluate to true, and

myComparator.like("digital","%cam%");

myComparator.like("digital","tal%");

should evaluate to false. Any ideas how to implement such a comparator or does anyone know an implementation with the same semantics? Can this be done using a regular expression?

解决方案

.* will match any characters in regular expressions

I think the java syntax would be

"digital".matches(".*ital.*");

And for the single character match just use a single dot.

"digital".matches(".*gi.a.*");

And to match an actual dot, escape it as slash dot

.

最后

以上就是舒适路灯为你收集整理的java sql like,如何在java中实现类似'LIKE'运算符的SQL?的全部内容,希望文章能够帮你解决java sql like,如何在java中实现类似'LIKE'运算符的SQL?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(55)

评论列表共有 0 条评论

立即
投稿
返回
顶部