diff --git a/src/main/java/tech/jhipster/lite/module/domain/replacement/RegexNeedleAfterReplacer.java b/src/main/java/tech/jhipster/lite/module/domain/replacement/RegexNeedleAfterReplacer.java index 1f4c55afc50..8340d422d8c 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/replacement/RegexNeedleAfterReplacer.java +++ b/src/main/java/tech/jhipster/lite/module/domain/replacement/RegexNeedleAfterReplacer.java @@ -19,7 +19,13 @@ public boolean notMatchIn(String content) { @Override public BiFunction replacement() { return (content, replacement) -> - linePattern().matcher(content).replaceAll(result -> result.group() + JHipsterModule.LINE_BREAK + replacement); + linePattern() + .matcher(content) + .replaceAll(result -> result.group() + JHipsterModule.LINE_BREAK + escapeSpecialCharacters(replacement)); + } + + private String escapeSpecialCharacters(String replacement) { + return replacement.replace("$", "\\$"); } private Pattern linePattern() { diff --git a/src/main/java/tech/jhipster/lite/module/domain/replacement/RegexNeedleBeforeReplacer.java b/src/main/java/tech/jhipster/lite/module/domain/replacement/RegexNeedleBeforeReplacer.java index 4cb3ee299d7..190952cd3bf 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/replacement/RegexNeedleBeforeReplacer.java +++ b/src/main/java/tech/jhipster/lite/module/domain/replacement/RegexNeedleBeforeReplacer.java @@ -19,7 +19,13 @@ public boolean notMatchIn(String content) { @Override public BiFunction replacement() { return (content, replacement) -> - linePattern().matcher(content).replaceAll(result -> replacement + JHipsterModule.LINE_BREAK + result.group()); + linePattern() + .matcher(content) + .replaceAll(result -> escapeSpecialCharacters(replacement) + JHipsterModule.LINE_BREAK + result.group()); + } + + private String escapeSpecialCharacters(String replacement) { + return replacement.replace("$", "\\$"); } private Pattern linePattern() {