💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### [`find()`](https://lingcoder.gitee.io/onjava8/#/book/18-Strings?id=find) `Matcher.find()`方法可用来在`CharSequence`中查找多个匹配。例如: ~~~ // strings/Finding.java import java.util.regex.*; public class Finding { public static void main(String[] args) { Matcher m = Pattern.compile("\\w+") .matcher( "Evening is full of the linnet's wings"); while(m.find()) System.out.print(m.group() + " "); System.out.println(); int i = 0; while(m.find(i)) { System.out.print(m.group() + " "); i++; } } } /* Output: Evening is full of the linnet s wings Evening vening ening ning ing ng g is is s full full ull ll l of of f the the he e linnet linnet innet nnet net et t s s wings wings ings ngs gs s */ ~~~ 模式`\\w+`将字符串划分为词。`find()`方法像迭代器那样向前遍历输入字符串。而第二个重载的`find()`接收一个整型参数,该整数表示字符串中字符的位置,并以其作为搜索的起点。从结果可以看出,后一个版本的`find()`方法能够根据其参数的值,不断重新设定搜索的起始位置。