Skip to content

Escaped characters get "un-escaped" when using Matcher.appendReplacement #18

@vprcic

Description

@vprcic

I don't know whether this is still maintained, but there's a bug when using the Matcher.appendReplacement that removes escaping of characters like "\s". Here's a code example:

Pattern pattern = Pattern.compile("[0-9]");
Matcher matcher = pattern.matcher("12345");
StringBuffer buffer = new StringBuffer();
while (matcher.find()) {
    matcher.appendReplacement(buffer, matcher.group() + "\\s");
}
matcher.appendTail(buffer);
System.out.println(buffer);

This should print "1\s2\s3\s4\s5\s" but prints "1s2s3s4s5s".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions