Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
github account with ecipse 1 42
netstat -ano | find "8000" and taskkill /f /pid 2984 3 37
varialbe initialization 11 30
Configure a Bean in an XML file 4 12
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

895 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

15 Experts available now in Live!

Get 1:1 Help Now