正则表达式问题
发布时间:2020-12-13 23:10:47 所属栏目:百科 来源:网络整理
导读:Pattern.compile部分匹配 String.matches()完全匹配,等同于Pattern.matches(regex,str) 如果要验证一个输入的数据是否为数字类型或其他类型,一般要用matches() 例: String str = "你好%你好";Matcher mat = Pattern.compile("[u4e00-u9fa5]+").matcher(s
Pattern.compile部分匹配 String.matches()完全匹配,等同于Pattern.matches(regex,str) 如果要验证一个输入的数据是否为数字类型或其他类型,一般要用matches() String str = "你好%你好"; Matcher mat = Pattern.compile("[u4e00-u9fa5]+").matcher(str); if (mat.find()) { System.out.println("matched"); } else { System.out.println("no matched"); } System.out.println(Pattern.matches("[u4e00-u9fa5]+",str)); System.out.println(str.matches("[u4e00-u9fa5]+")); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |