A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

public static void main(String[] args) throws Exception {
     String [] str ={"16210626656","18601066888","13912387666","13156166693","15115888028"};
     String regex ="[1][358][0-9]{6}(\\d){3}";
     Pattern p = Pattern.compile(regex);
     Matcher m = p.matcher(str);
     boolean b = m.matches();
     while(m.find()){System.out.println(m.group());}
        }
-----------------------------------------------------------------------
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
        The method matcher(CharSequence) in the type Pattern is not applicable for the arguments (String[])

        at day14_try.Num2.main
---------------------------------------------------------------------我都无语了,怎么回事呢

1 个回复

倒序浏览
boolean b = m.matches();     //这一句不要,错误的;
正确的代码这样写,你试试:
String str ="我的手机是18511866260,我曾用过18987654321,还用过18812345678";  //不用String[ ]看看
     String regex ="[1][358][0-9]{6}(\\d){3}";
     Pattern p = Pattern.compile(regex);
     Matcher m = p.matcher(str);
     boolean b = m.matches();
     while(m.find()){
            System.out.println(m.group());}
     }
回复 使用道具 举报 1 0
您需要登录后才可以回帖 登录 | 加入黑马