I want to replace the replaceEntry (@length) with newEntry but there are some replaceEntrys with additional content I don't want to be replaced (eg @length.article). If I just look for the pattern without grouping it, it replaces the replaceEntry and the following char but I just want to replace the entry. Is the Regex wrong or something else?
private String replace(String code){
String code = "@length Lorem ipsum dolor sit amet, consetetur sadipscing elitr, @length.article sed diam 
               nonumy eirmod tempor invidunt ut labore et dolore magna @length.media aliquyam erat, sed 
               diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd 
               gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem @length_name 
               ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt 
               ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et 
               justo duo dolores et @length ea rebum. Stet clita kasd gubergren, no sea takimata sanctus 
               est Lorem ipsum dolor sit amet. @length";
String replaceEntry = "@length";
String newEntry = "@column";
Pattern pattern = Pattern.compile("(" + replaceEntry + ")([^\\w-\\.])");
        Matcher matcher = pattern.matcher(code);
        String newCode = code.replaceAll(matcher.group(1), newEntry);
        return newCode;
}
 
     
     
    