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

后端 未结 15 1444
你的背包
你的背包 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条回答
  •  执念已碎
    2020-11-29 04:07

    .* 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

    \.
    

提交回复
热议问题