Java 正则表达式与目标不匹配

Java 正则表达式与目标不匹配,java,regex,Java,Regex,假设我们有如下字符串列表-admin、sam1、sam2、max、maximus Then in search box if I give *a*m* should return admin *sam* should return sam1,sam2 m* should return max,maximus max* should return max,maximus 等等 我的代码如下(示例代码,不查看列表):- 还有一些,输出为假,但必须为真:

假设我们有如下字符串列表-admin、sam1、sam2、max、maximus

Then in search box if I give 
     *a*m* should return admin
     *sam* should return sam1,sam2
     m* should return max,maximus
     max* should return max,maximus
等等

我的代码如下(示例代码,不查看列表):-

还有一些,输出为假,但必须为真:

  1. private static final String REGEX = ".*ad*.";
     private static final String INPUT = "admin";

  2. private static final String REGEX = ".*max*.";
     private static final String INPUT = "max11";

  3. private static final String REGEX = ".*sa*.";
     private static final String INPUT = "sam1";  

您的正则表达式是不正确的,正如在

这个正则表达式的意思是:

  • *
    零个或多个字符
  • 文字
    a
  • d*
    零个或更多
    d
    字符
  • 任何字符
相反,它应该是:

.*ad.*
这意味着:

  • *
    零个或多个字符
  • 文字
    ad
  • *
    零个或多个字符

我不确定您的模式,您能否将
*ad*
更改为
*ad*
?上面的注释指出了您的错误并解决了它。
.*ad*.
.*ad.*