Java Regex 2 - Duplicate Words

  • + 1 comment

    I don't think the test cases are quite evil enough. The code above will fail for input of smoothe the the theorem (it outputs smoothe theorem, not smoothe the theorem).

    The replaceAll should be more like replaceAll("\\b"+ m.group()+"\\b",m.group(1)) to prevent mismatches in this second regex.