`

java 正则

    博客分类:
  • java
阅读更多
\d 数字0-9
\D 非数字[^0-9]
\s 空白字符[ \t\n\x0B\f\r]
\S 非空白字符[^\s]
\w 数字字母下划线
\W [^\w]

出现次数

? 0或1
* >=0
+ >=1
{x} x次
{x,} >=x
{x,y} >=x && <=y

		String testStr = "f3j39fl3k";
		String reg = "[0-9]+";
		Pattern pattern = Pattern.compile(reg);   
        Matcher matcher = pattern.matcher(testStr);
        System.out.println(matcher.matches());//false 检测是否完全匹配
        String result = "";
        while (matcher.find()) {
           result = matcher.group();
           System.out.println(result);
           /*
            * 3
			* 39
			* 3
            */
        }
        result = matcher.replaceAll("AAA");
        System.out.println(result);//fAAAjAAAflAAAk
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics