我也不知道对错,尝试着写的,仅供参考,如有错处,望诸位前辈指点,谢谢。
package example01;
import java.util.regex.*;
public class Find {
public static void main(String[] args) {
String str = "abcdefg12345";
String regex = "[a-zA-Z]+[0-9]+";
Pattern p = Pattern.compile(regex);
Matcher matcher = p.matcher(str);
if (matcher.find()) {
System.out.println(matcher.group());
}
}
}
运行结果是这个亚子

本文分享了一个使用Java正则表达式进行字符串匹配的例子,通过Pattern和Matcher类实现对特定模式的查找。
1436

被折叠的 条评论
为什么被折叠?



