加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式!是这样写滴~

发布时间:2020-12-14 01:45:27 所属栏目:百科 来源:网络整理
导读:?? 匹配2到4个中文字符(用于匹配姓名):[u4e00-u9fa5]{2,4} 匹配电子邮箱:^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$(用于jsp) w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*(用于java) 匹配手机号码:[0-9]{11} 以上为比较常用的正则表
??

匹配2到4个中文字符(用于匹配姓名):[u4e00-u9fa5]{2,4}

匹配电子邮箱:^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$(用于jsp) w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*(用于java)

匹配手机号码:[0-9]{11}


以上为比较常用的正则表达式,下面实例介绍它怎么用:



String input = "张三丰,zhangs@qq.com,我要预订产品哦!";


//邮箱检测
String regex_email = "w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*"; Pattern pattern_email = Pattern.compile(regex_email); Matcher matcher_email = pattern_email.matcher(input); while (matcher_email.find()) { email=matcher_email.group(); System.out.println("邮箱:"+matcher_email.group()); } //手机号检测 String regex_phone = "[0-9]{11}"; Pattern pattern_phone = Pattern.compile(regex_phone); Matcher matcher_phone = pattern_phone.matcher(input); while (matcher_phone.find()) { phone=matcher_phone.group(); System.out.println("手机号:"+matcher_phone.group()); }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读