package com.example.demotest.controller;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @Author shaolin
* @Date 2024-03-29 13:51
**/
public class Demo {
public static void main(String[] args) {
String text = "测试leishaolin@163.com.cn开启静默";
Pattern emailPattern = Pattern.compile("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}");
Matcher matcher = emailPattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}
java 正则获取文字中的邮箱
![](https://img-home.csdnimg.cn/images/20240711042549.png)