相当于一个小工具,记录一下。
import java.util.regex.Matcher; import java.util.regex.Pattern; //正则表达式实例,查找数据中的邮箱手机号和座机号 public class Regex { public static void main(String[] args) { //初始数据 String rs = "****************,电话020-43556656,或联系邮箱" + "[email protected],电话15373433634,030555574" + "邮箱[email protected],40085446745,400657367"; //制定正则表达式,查找邮箱,手机号和座机号 String regex = "(\\w{1,30}@[a-zA-Z0-9]{2,20}(\\.[a-zA-Z-0-9]{2,20}){1,2})|" + "(1[3-9]\\d{9})|(0\\d{2,6}-?\\d{5,20}|(400-?\\d{3,9}-?\\d{3,9}))"; //把规则编译成匹配对象 Pattern pattern = Pattern.compile(regex); //得到内容匹配器对象 Matcher matcher = pattern.matcher(rs); //开始查找 while (matcher.find()) { String rs1 = matcher.group(); System.out.println(rs1); } } }Regex
标签:regex,String,正则表达式,matcher,查找,邮箱 From: https://www.cnblogs.com/Excusezuo/p/16593023.html