Java String ReplaceAll method giving illegal repetition error?

A { is a regex meta-character used for range repetitions as {min,max}. To match a literal { you need to escape it by preceding it with a \\:

str = str.replaceAll("\\{", "\n"); // does work

Leave a Comment