Solved

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

Posted on 2008-06-23
4
174 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
  • 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

705 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now