Solved

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

Posted on 2008-06-23
4
180 Views
Last Modified: 2010-03-30
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
Comment
Question by:paries
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 21852572
Its the * you want escape \*, it has special meaning in a regexp
0
 
LVL 7

Expert Comment

by:humanonomics
ID: 21852585
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
 
LVL 7

Expert Comment

by:humanonomics
ID: 21852587
Oops sorry, ignore my previouse comment, that will erase everything, need to work more on it.
0
 
LVL 7

Accepted Solution

by:
humanonomics earned 500 total points
ID: 21852661
Try this one.

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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question