[Solved] How to replace a substring with ( from a string


This regex

String a = "Want to Start (A) Programming and (B) Designing";
String b = a.replaceAll("\\(", "\n\\(");
System.out.println(b);

results in

Want to Start 
(A) Programming and 
(B) Designing

Just escape the brackets with \\ and you’re fine.

Edit:
more specific, like mentioned below

a.replaceAll("(\\([AB]\\))", "\n$1"); to match only (A) and (B) or

a.replaceAll("(\\(\\w\\))", "\n$1"); to match any (*) (Word character)

1

solved How to replace a substring with ( from a string