How to implement a SQL like 'LIKE' operator in java?

后端 未结 15 1446
你的背包
你的背包 2020-11-29 03:12

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

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


        
15条回答
  •  Happy的楠姐
    2020-11-29 03:45

    Check out https://github.com/hrakaroo/glob-library-java.

    It's a zero dependency library in Java for doing glob (and sql like) type of comparisons. Over a large data set it is faster than translating to a regular expression.

    Basic syntax

    MatchingEngine m = GlobPattern.compile("dog%cat\%goat_", '%', '_', GlobPattern.HANDLE_ESCAPES);
    if (m.matches(str)) { ... }
    

提交回复
热议问题