When some metacharacters are placed within brackets, no need to escape.
In another way, I do not know if you mean escape *
with \*
. In that case, try the next:
String newStr = str.replace("*", "\\*");
EDIT: There is something curious in your regular expressions.
(?=\[*])
Look ahead for the character[
(0 or more times), followed by]
(?=[]\[*])
Look ahead for one of the next characters:[
,]
,*
Perhaps the regex that you are looking for is the following:
(?=\*)
In Java, "(?=\\*)"