具有多级条件的Java String Regex

问题描述 投票:-5回答:1

我想在字符串中找到一个字符串,这是我的场景:

String toMatch = "ABC";
String matchIn = "ABC*FED";

matchIng的其他变体:

matchIn = "ABC";
matchIn = "ASD*ABC";
matchIn = "JULY*ABC*RTEW";

我已经提出了这个正则表达式,但它显然不起作用:

matchIn.matches(".*(\\*)?" + toMatch + "(\\*)?.*");

这里的问题是,我不知道如何查找"*"只有当它后面跟着另一个词时。这样它只是匹配所有内容,例如,toMatch="ABCDEF"在不应该的时候返回true!

java regex string
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.