Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

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

0
paries
Asked:
paries
  • 3
1 Solution
 
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
 
humanonomicsCommented:
Try this one.

String nodeStr = trial.replaceAll("/\\*?[^>]+\\*/", "");
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now