您的位置:首页 > 其它

正则表达式 分组 还有\\1 总结。。

2017-04-09 14:07 169 查看
转载来自:http://bbs.itheima.com/thread-7177-1-1.html

"(\w)((?=\1\1\1)(\1))+

1. (\w) -- \w,一个字符,括号表示一个子匹配,第一个括号是"\1",第二个括号是"\2",……。
2. (\w)(\1) -- 一个字符,后面紧跟一个相同的字符。

                // Pattern pattern = Pattern.compile("(\\w)((?=\\1\\1\\1)(\\1))+");

                Pattern pattern = Pattern.compile("(\\w)(\\1)");

                Matcher matcher = pattern.matcher("aaa ffffff 999999999");

                // Matcher matcher = pattern.matcher("aaa 999999");

                while (matcher.find()) {

                        System.out.print(matcher.group()+" | ");

                }

("aaa ffffff 999999999");aa | ff | ff | ff | 99 | 99 | 99 | 99 |

2. (\\w)(?=\\1\\1\\1)
 Pattern.compile("(\\w)(?=\\1\\1\\1)");

运行得:f | f | f | 9 | 9 | 9 | 9 | 9 | 9 | ,

四个字符连续相同才符合条件,且 index只+1(6个 f 所以是3个了)

ffffff 输出:f | xxx)

后面继续验证的,看懵了,先码后看。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: