trying to remove c like comments with regex. i am sure it is a escape thing

hello,
i am parsing a file and have a line that looks like
body{/* 1 */
i am trying to replace /*something*/ with "" so it would look like
body{

i tried
nodeStr = nodeStr.replaceAll("\\/*/?\\w++[^>]*+*\\/", "");

thanks for any help
Randy

pariesAsked:
Who is Participating?
 
humanonomicsCommented:
Try this one.

String nodeStr = trial.replaceAll("/\\*?[^>]+\\*/", "");
0
 
objectsCommented:
Its the * you want escape \*, it has special meaning in a regexp
0
 
humanonomicsCommented:
I presume you want to get rid of the complete comment including the contents.
try the following regex it will work.

nodeStr =nodeStr.replaceAll("[(/\\*\\S\\s\\*/)]", "");
0
 
humanonomicsCommented:
Oops sorry, ignore my previouse comment, that will erase everything, need to work more on it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.