本帖最后由 fantacyleo 于 2014-9-22 20:22 编辑
- public static void main(String[] args) {
- String s = "erkktyqqquiozzzzzo";
- Pattern p = Pattern.compile("([a-z])\\1+");
- Matcher m = p.matcher(s);
- StringBuilder sb = new StringBuilder();
- int start = 0;
- int end = 0;
- while (m.find()) {
- end = m.start();
- if (start < end)
- sb.append(s.substring(start, end));
- String matched = m.group();
- for (int i = 0; i < matched.length(); i++)
- sb.append("#");
- start = m.end() + 1;
- }
- System.out.println(sb.toString());
- }
复制代码 |