java---正则表达式(5)
来源:互联网 发布:校园软件推广方案 编辑:程序博客网 时间:2024/06/06 20:45
package com.beicai.zhengze;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TestPattern {
public static void main(String[] args) {
// Pattern p = Pattern.compile("a*b");//获取到了正则表达式
// Matcher m = p.matcher("aaaaab");//返回一个匹配器Matcher
// boolean b = m.matches();//看是否能匹配,匹配就返回true
// System.out.println(b);
System.out.println("aaaaab".matches("a*b"));
//把一个字符串中的手机号码获取出来
String s = "我的手机号码是18234821616,曾经用过15235250006,还用过17600276674";
String regex = "1[3578]\\d{9}";//手机号码的正则表达式
// Pattern p = Pattern.compile(regex);
// Matcher m = p.matcher(s);
// boolean b = m.matches();
// System.out.println(b);
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(s);
// boolean b = m.find();
// System.out.println(b);
// String s1 = m.group();
// System.out.println(s1);
while(m.find()){
System.out.println(m.group());
}
}
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TestPattern {
public static void main(String[] args) {
// Pattern p = Pattern.compile("a*b");//获取到了正则表达式
// Matcher m = p.matcher("aaaaab");//返回一个匹配器Matcher
// boolean b = m.matches();//看是否能匹配,匹配就返回true
// System.out.println(b);
System.out.println("aaaaab".matches("a*b"));
//把一个字符串中的手机号码获取出来
String s = "我的手机号码是18234821616,曾经用过15235250006,还用过17600276674";
String regex = "1[3578]\\d{9}";//手机号码的正则表达式
// Pattern p = Pattern.compile(regex);
// Matcher m = p.matcher(s);
// boolean b = m.matches();
// System.out.println(b);
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(s);
// boolean b = m.find();
// System.out.println(b);
// String s1 = m.group();
// System.out.println(s1);
while(m.find()){
System.out.println(m.group());
}
}
}
阅读全文
0 0
- java---正则表达式(5)
- Java 正则表达式正则
- 【正则表达式】Java正则表达式
- 正则表达式 JAVA正则表达式
- 【Java】【正则表达式】正则表达式
- Java 正则表达式详解_正则表达式
- java正则表达式!正则表达式踩坑!!!
- 正则表达式工具类,正则表达式封装,Java正则表达式
- Java script 正则表达式(5)
- (5)正则表达式——Java
- Java正则表达式详解
- Java正则表达式详解
- Java正则表达式详解
- Java正则表达式详解
- Java正则表达式详解
- java和正则表达式
- java正则表达式详解!
- Java正则表达式详解
- 第四周项目 项目3
- 机器学习(20)之Adaboost算法原理小结
- 为什么有些语言会比别的快?
- Delphi中编辑框只能输入数字或者只能输入一个浮点数值
- led驱动
- java---正则表达式(5)
- 使用C++类模板,出现链接错误
- JVM内存理解
- (05)oracle新人笔记------子查询(重点)
- The content of element type "configuration" must match "EMPTY". Children of type "comment" are not a
- android多个button监听点击事件-法二
- Dalvik模式下System.loadLibrary函数的执行流程分析
- C# 命名空间 (Namespace)
- zkpython 安装