import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String[] args) {
Pattern pattern=Pattern.compile("[0-9]+"); // 匹配数字位从一个到九个中间一个到多个
Matcher m=pattern.matcher("1234");
boolean mathes=m.matches();
System.out.println(mathes);
Pattern pattern1=Pattern.compile("\\d"); //匹配 数字
Matcher m1=pattern.matcher("1234");
boolean mathes1=m1.matches();
System.out.println(mathes1);
Pattern pattern2=Pattern.compile("\\w"); // 表示匹配字母
Matcher m2=pattern.matcher("ssss");
boolean mathes2=m2.matches();
System.out.println(mathes1);
}
}
本文介绍了使用Java正则表达式进行数字匹配的基本操作,包括单个数字、多个连续数字和字母字符的匹配。
9万+

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



