Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-06-23
4
Medium Priority
?
183 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 2000 total points
ID: 21852661
Try this one.

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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.
Suggested Courses

972 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