3 回答
TA貢獻(xiàn)1833條經(jīng)驗(yàn) 獲得超4個(gè)贊
public static void main(String[] args) {
String test = "something hear - to - find some to or tows";
System.out.println("1.result: " + contains("- to -( \\w+) som", test, null));
System.out.println("2.result: " + contains("- to -( \\w+) som", test, 5));
}
static boolean contains(String pattern, String text, Integer fromIndex){
if(fromIndex != null && fromIndex < text.length())
return Pattern.compile(pattern).matcher(text).find();
return Pattern.compile(pattern).matcher(text).find();
}
1.結(jié)果:正確
2.結(jié)果:正確
添加回答
舉報(bào)
