我想在字符串中找到一个字符串,这是我的场景:
String toMatch = "ABC";
String matchIn = "ABC*FED";
matchIng的其他变体:
matchIn = "ABC";
matchIn = "ASD*ABC";
matchIn = "JULY*ABC*RTEW";
我已经提出了这个正则表达式,但它显然不起作用:
matchIn.matches(".*(\\*)?" + toMatch + "(\\*)?.*");
这里的问题是,我不知道如何查找"*"
只有当它后面跟着另一个词时。这样它只是匹配所有内容,例如,toMatch="ABCDEF"
在不应该的时候返回true!