新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
正則表達式如何正確在Java項目中使用-創(chuàng)新互聯(lián)
這篇文章將為大家詳細講解有關(guān)正則表達式如何正確在Java項目中使用,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
1.匹配驗證-驗證Email是否正確
public static void main(String[] args) { // 要驗證的字符串 String str = "service@xsoftlab.net"; // 郵箱驗證規(guī)則 String regEx = "[a-zA-Z_]{1,}[0-9]{0,}@(([a-zA-z0-9]-*){1,}\\.){1,3}[a-zA-z\\-]{1,}"; // 編譯正則表達式 Pattern pattern = Pattern.compile(regEx); // 忽略大小寫的寫法 // Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(str); // 字符串是否與正則表達式相匹配 boolean rs = matcher.matches(); System.out.println(rs); }
網(wǎng)頁標題:正則表達式如何正確在Java項目中使用-創(chuàng)新互聯(lián)
文章地址:http://ef60e0e.cn/article/pdggd.html