這是我的代碼,在給定的字符串中查找"ab"
模式。正則表達式查找方法
import java.util.regex.*;
public class RegExp
{
public static void main(String[] args)
{
Pattern p = Pattern.compile("ab");
Matcher m = p.matcher("ababbaba");
while(m.find())
{
System.out.println(m.start());
}
}
}
,但我無法理解的find()
和start()
內部工作。
要理解內部工作,您應該閱讀來源。但也許你想解釋你期望看到什麼,以及你不明白的是什麼。 – RealSkeptic
經典「閱讀精美手冊」的問題。 https://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html#find() –
@RealSkeptic恰到好處。你寫了我在我的回答中添加的同樣的建議:) – freedev