JAVA常用正则表达式(邮箱、链接、中英文、IP地址等)

import java.util.regex.Pattern;

/**
 * @author LiFucheng
 * @version 1.0
 * @description: TODO 常用正则表达式
 * @date 2022/5/2 18:19
 */
public class PatternUtil {
    private static final Pattern email = Pattern.compile("\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}");
    private static final Pattern url = Pattern.compile("[a-zA-z]+://[^\\s]*");
    private static final Pattern english = Pattern.compile("^[A-Za-z0-9]+$");
    private static final Pattern chinese = Pattern.compile("^[\\u4e00-\\u9fa5]{0,}$");
    private static final Pattern phone = Pattern.compile("^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$");
    private static final Pattern qq = Pattern.compile("^[1-9][0-9]{4,10}$");
    private static final Pattern wechat = Pattern.compile("^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$");
    private static final Pattern ipv4 = Pattern.compile("^((25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]?\\d)\\.){3}(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]?\\d)$");
    private static final Pattern ipv6 = Pattern.compile( "^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$");

    public static boolean matchEmail(String src) {
        if (src == null) return false;
        return email.matcher(src).matches();
    }

    public static boolean matchUrl(String src) {
        if (src == null) return false;
        return url.matcher(src).matches();
    }

    public static boolean matchEnglish(String src) {
        if (src == null) return false;
        return english.matcher(src).matches();
    }

    public static boolean matchChinese(String src) {
        if (src == null) return false;
        return chinese.matcher(src).matches();
    }

    public static boolean matchPhone(String src) {
        if (src == null) return false;
        return phone.matcher(src).matches();
    }

    public static boolean matchQQ(String src) {
        if (src == null) return false;
        return qq.matcher(src).matches();
    }

    public static boolean matchWechat(String src) {
        if (src == null) return false;
        return wechat.matcher(src).matches() || matchPhone(src);
    }

    public static boolean matchIPV4(String src) {
        if (src == null) return false;
        return ipv4.matcher(src).matches();
    }

    public static boolean matchIPV6(String src) {
        if (src == null) return false;
        return ipv6.matcher(src).matches();
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

54号考生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值